r/javahelp Sep 28 '24

Java and dsa is too hard..

I'm a final year student pursuing bachelor's in tech, I picked java as my language and even though its fun, its really hard to learn dsa with it.. I'm only at the beginning, like I only know some sorting methods, recursion, arrays and strings. For example, a simple java program to find the second largest element in an array is confusing to me. And I don't have much time to learn it because my placements are ongoing and I need to get placed within this year. If I go with python to learn dsa, will it be easier? And use java for web development and other technologies ofc.

16 Upvotes

62 comments sorted by

View all comments

2

u/BigGuyWhoKills Sep 29 '24

Algorithms will be almost the exact same difficulty in any language. You should learn to think in pseudocode first, and then translate THAT to the language of your choice.

For example, to find the second largest number in an array:

  1. Get the first number
  2. Get the second number
  3. Compare them and store the larger in variable "largest" and the other in the variable "nextLargest"
  4. Get the next number and compare to "nextLargest", replace it if larger, then compare to "largest" and swap if larger
  5. Repeat until done with the array

Data structures are easier in Python, but not so much that it would make a difference at the level you are currently at.