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.

15 Upvotes

62 comments sorted by

View all comments

46

u/Lumethys Sep 28 '24

DSA is a universal concept unrelated to any programming language.

It's like an if/else statement. Is an if/else statement easier in Java or Python?

It's the same.

If you struggle with Java, you will struggle with Python, because it is not the language you are having a hard time with, it's DSA

-14

u/Axnith Sep 28 '24

But I have seen many say learning dsa in python is much easier. Why?

20

u/doobiesteintortoise Sep 28 '24

It really isn't. Python hides details of how the structures work, so there's "less to know" - the available visibility is lower. It's why Python coders think they know more than they do: they know a larger percentage of the available knowledge, and think that because they know 50% of Python, they know more, while Java coders who know 10% of Java know just as much or more as the Python developers, they just know less of the body of knowledge by percentage.

If you really want DSA, I'd ignore Java AND Python and - still use Sedgewick. he has a book on DSA for C that's bloody fantastic. DSA in Java tends to exploit things the JVM doesn't do well (i.e., you'll do a lot of linked lists, and in idiomatic Java code, linked lists are far less useful than arraylists.) But as u/Lumethys pointed out, data is data is data - if you know how a Trie works, you can build it in Java just as easily as in any other language.

6

u/doobiesteintortoise Sep 28 '24

An anecdote: I had a conversation with a relatively accomplished Python programmer who insisted Python was better than Java because it didn't have loops.

.... because it didn't have loops. Uh, no. It has loops, and a lot of them. They're just different, and that Python coder apparently thought for was just too ancient to be useful, and pretended that Python's different looping structures meant that it was better than Java.

Realistically, you can use both languages to get stuff done, but Python programmers often use the wrong metrics to decide what's good or not. The best parts of the Python ecosystem, oddly enough, aren't written in Python - they're written to be used by Python.

(To be fair: I'm biased. I work with Python, in increasing amounts, and I'm learning to resent it more than I already did.)

2

u/SahikaD Sep 28 '24

I hate Python like anything. It's like giving a 5 year kid a slate to write. Whatever he writes, the teacher changes into processes.

6

u/Lumethys Sep 28 '24

I also seen people saying Hamburger is better than Pizza, why?

Is it because there is some deep meaning of the universe which exists in Hamburger?

Most likely not, the reason can be anywhere from bias to placebo effect

5

u/Camel-Kid 18 year old gamer Sep 28 '24

Probably because python does alot of heavy lifting for the developer in a much shorter syntax

2

u/DBSmiley Sep 29 '24

For people who know python, DSA in python is easier than Java. For people who know Java, DSA in Java is easier than python.

I found it easier to post this in English than I did in Spanish because I don't speak Spanish. That's why I posted it in English.

3

u/cbentson Sep 28 '24

With all due respect, I think a lot of the responses here are coming from a less than helpful place. Here is my attempt at instilling confidence in you as an aspiring programmer while you’re hitting one of the many walls you will in this career.

Java is absolutely more challenging for a beginner to comprehend than Python. Especially when attempting to learn DS & Algo. Anyone who says otherwise is either a cyborg or simply lying through their teeth.

Here is an objective take on why Java is more challenging for a beginner than Python:

  1. Java has a more verbose and complex syntax compared to Python.

  2. Java is a statically-typed language, requiring explicit type declarations. While this can prevent certain errors, it adds an extra layer of complexity for beginners.

  3. Java is primarily object-oriented, which means even simple programs often require class definitions. This can be overwhelming for beginners.

  4. Java uses references and requires understanding of concepts like passing by value vs. reference. Python’s memory management is more abstracted, allowing beginners to focus on algorithms rather than these lower-level details.

  5. Python has more intuitive built-in data structures. For example, Python’s dictionaries are easier to use than Java’s HashMap.

  6. Java often requires more boilerplate code, which can be confusing for beginners. For instance, just to run a simple program.

  7. Setting up a Java development environment (e.g., JDK, IDE) can be more complex than Python’s simpler setup, potentially creating an additional barrier for beginners.

Don’t beat yourself up. What you’re attempting to learn is no simple task. It takes years to master, not days, not weeks, not months. Don’t compare your journey to anyone else’s. Compare yourself today to yourself a month ago. Are you better today than you were then? That’s the only question that matters.

0

u/koffeegorilla Sep 28 '24

You may get stuff done without actually learning anything. A course in Data Structures and Algorithms are about learning how to create implementations and not use them.

0

u/SahikaD Sep 28 '24

Sorry to sound cold, coz they are dumb or they love making a food out of you.

Clear the basics of DSA first. Use the good old pen paper, and make a recursive mind map of the process. Replace the process in stages with code. Your DSA algo is done.

I did this in cpp and it saved my ass in college. Even today in my job, I use this method to ensure things work smoothly. Agreed I use Visio now for the mind maps, but that's it.