r/learnjava • • Jul 11 '20

At what point should I start with data structures and algorithms in java, and what resources should I use?

So I have been learning java from past 15 days , but I don't have a strong grasp on it , I have some experience coding in C and Python, can you tell me what topics should I cover in Java Core before starting with DS & Algo part?

Also I was thinking of doing data structures from William fiset's youtube playlist and practicing on leetcode explore cards. (Also hackerrank)Is this a good idea? Can anyone give me some reviews whether or not should I use leetcode explore because they seem pretty organised to me.

After that or parallelly I was thinking of doing the Princeton's Algorithm course.

I want suggestions on whether or not the resources I have chosen are sufficient and good enough, or if there are better ones please recommend me some.

Thanks in advance.

45 Upvotes

25 comments sorted by

16

u/coder970 Jul 11 '20

If you have coding experience in C and Python, why not use them for DSA? Try these problems solved in C/C++, Java and Python.

6

u/salmnakhhan09 Jul 11 '20

This problems really help. I started doing this problems and I have solved around 45 50 arrays based problem and it's really helpful.

0

u/bhavik911 Jul 11 '20

Actually i wanted to implement them in java itself

8

u/iamsooldithurts Jul 12 '20

The problem with your answer is that DSA are language agnostic. If you can’t solve them in a language you are familiar with, you’re not going to be solving them in languages you’re learning.

Basically, possibly criminally oversimplifying the issue, they all run on the same hardware, so the solution itself is basically the same in every language. The main differences between languages are in how you establish the particular data structures and the syntax behind the algorithms.

An array is an array in any language. The same goes with for/while/etc loops. And recursion. And pretty much any algorithm you care to mention.

1

u/bhavik911 Jul 12 '20

The thing is that many companies require either Java or C++ for developer jobs , because of which I wanted to shift from python to java.

4

u/Farpafraf Jul 12 '20

yeah but with algo you are not really learning a specific language, doing algo in Java won't teach you how to use java imho, I would consider phyton a better choice to do algo or better yet you can just use pseudocode

2

u/Dokiace Jul 12 '20

that link is a goldmine, now how do I actually keep this link so I wont forget about it

1

u/unpronounceable Jul 12 '20

You can click the "save" button on the comment and it will save it to your "saved" list under your profile.

15

u/Nephyst Jul 12 '20

Aside from someone just starting out learning the basics, data structures and algorithms are the core skills that separate great developers from mediocre ones. Interviewing at mid/senior/lead levels will revolve around these skills at any decent dev shop. Even after programming for a dozen years I am still working on improving these skills, and I use them daily in my career.

All programming, regardless of what language you are using, comes down to how you structure, access, and manipulate data. The data structures you choose will necessarily dictate how you can access that data, and the better you understand the nuances between the options you have the better your ability to solve complex problems will be. They also have important implications on the performance of the code you write.

For some java specifics: It's not important that you memorize how to code a HashMap, or how to write a specific sorting algorithm. An example of what is important is understand how a HashMap works, and the time complexity of operations like inserting, accessing, and removing data from a HashMap. How does a HashMap compare to a HashSet? Why would you use one over the other? How do they compare to an ArrayList? How does an ArrayList compare to a LinkedList? What are stacks and queues, and when would I want to use them? How does each data structure handle null values? Can you use the datastructure in a multi-threaded environment? What about heaps, trees, singletons, etc?

You don't necessarily have to memorize every detail of every data structure. I often look up the java documentation to remind myself of specifics. But you should have a solid understanding of what is available to use and also know how to find the details that are important when you need them.

Time complexity is known as "big-O notation" and is written like O(1), O(n), O(log N), and it's important that you have at least a basic understanding on what these mean. They give you a way of comparing two algorithms and making statements like "As the input size grows, algorithm A is going to take exponentially longer to complete than algorithm B".

There are a lot of websites dedicated to working on these skills, like leetcode, project euler, hacker rank, etc.

1

u/bhavik911 Jul 12 '20

Thanks for such a detailed answer , will keep this in mind.

3

u/masdfi Jul 12 '20

To be honest, I don't know the youtube playlists and courses you mentioned and on top of that I am not sure what overall programming knowledge level you do have with your prior experience in C and Python.

What I think you need is a good basement to build your java knowledge ontop to guide you while getting more experience. As with every language java has it's edges and its standard library need to be learned as well.

I've been a professional java programmer for almost 10 years and can recommend one book for every java programmer working on entry, intermediate or expert level Java knowledge alike:

Effective Java 3rd Edition

From my experience this book is one of, if not the best collection of basics, best practices, and recommendations for java programming. I've read both the 1st and 3rd edition of this book and I'm still getting back to it sometimes.

It covers in total 90 best pratices for objects, common methods (equals&hashcode), classes and interfaces, generics, enums, annotations, lambda and streams, methods, java coding in general, exception handling, concurrency and serialization. Have a look at the link i added, to see the table of contents.

This is not at all a replacement for programming practice or what the princeton course will teach you, but it provides you with lessons&knowledge others had to learn themselves (sometimes the hard way ... I'm looking at you HashMap & Object.hashcode 😉) and will be a good book to get back to when facing specific problems e.g. when theres a need to implement concurrent processes.

Happy coding!

Bonus: If you want a good introduction to design principles in the context of Java on top, then I can recommend you the following conference talk:

Core Design Principles for Software Developers by Venkat Subramaniam

It's both entertaining and full of knowledge.

1

u/bhavik911 Jul 12 '20

Thanks for the recommendation , I will check them out.

2

u/salmnakhhan09 Jul 12 '20

Hi, how are u ? I am fresher not yet started working still looking for job. But I will share you my experience,
Solving DSA problem is a very big topic it can't be covered so easily and as a freshers looking for job they(company or a interviewer) is not going to see how many algorithm you can solve, so don't wory about grasping everything all at once it will confuse u as well as demotivate you to learn coding. As you you have said you got a little experience in c and python, And learning java for 15 days.

First make sure that you have all java concepts are clear to you,
Mainly java OOPS(inheritance, Abstraction, Polymorphism, Encapsulation) make sure you have a clear idea about this topics. Try this try solving all the questions this will cover you up all the java concepts plus while solving all this questions you will get an idea about how to solve problems. Remember a interviewer will never see how many algorithms you can solve rather he/she will see how will you solve a given question and this comes only by practising. Sorry for long post and be consistent Good luck

1

u/bhavik911 Jul 12 '20

Hey, thanks for the advice.

I am a fresher too btw :p

2

u/crazylegs888 Jul 12 '20

I found this website and I'm in absolute love. I feel like it's the best coding exercise site on the web.

https://edabit.com

1

u/bhavik911 Jul 12 '20

Thanks I will check it out

5

u/[deleted] Jul 11 '20

I'm still in college, but I think once you learn how to use objects in Java would be good.

1

u/un_prophete Jul 12 '20 edited Jul 12 '20

Look up cs61b it is Berkeley course accessible to public

2

u/bhavik911 Jul 12 '20

cs 61b is the berkley course maybe as far as i know

1

u/un_prophete Jul 12 '20

I think you might be right. It has been a while

3

u/j619s Jul 12 '20

Learn till Java Collections then start learning DS&Algo along with rest of the Java.

1

u/[deleted] Jul 12 '20

Yes. If you are set on using Java for learning/implementing algorithms, learn the collections API like the back of your hand. Look at the heirarchies and the important interfaces. Learn a little about lambdas so you can more easily use comparators. Learn how the collections are implemented; implement them yourself for the best practice.

0

u/[deleted] Jul 12 '20

[deleted]

1

u/bhavik911 Jul 12 '20

Does it cover only the algorithms part or it includes ds and algo both?

Can a beginner like me in data structures start that book without any difficulty?

0

u/[deleted] Jul 13 '20

[deleted]

1

u/bhavik911 Jul 14 '20

Definitely, sounds good. :)

0

u/[deleted] Jul 14 '20

[deleted]

1

u/bhavik911 Jul 22 '20

Hey , sorry for the late reply Not a frequent user. We can chat on discord for sure