# How do I learn algorithms and data structures? [closed]

This is in continuation to my previous question where I asked is it necessary to learn algorithms and data structures. I feel yes it is.

Now I work in an environment where I won't ever get the chance to learn it by experimenting or practically or in any assignment. What is the right approach like the right books, right kind of problems, right kind of resources that I can go through to give six months or a year or two to learn algorithms and data structures? And also mold my mind in a way that it can relate problems to data structures and algorithms.

• Cormen is your friend :) Commented Jan 2, 2011 at 1:23
• @lukas: Still haven't finished it though, there's quite a few maths in there that I am not that comfortable with. It did much more to my knowledge of algorithms, data structures and their analysis, that any other single source though :) Commented Jan 2, 2011 at 18:28
• You may also try my project, which describes popular algorithms and data structures more straightforwardly than wikipedia and contains souce codes almost for every article (structure, approach, algorithm)... en.algoritmy.net Commented Nov 29, 2011 at 21:38

Read everything about algorithm and design you can possible find. There are phenomenal books out there. The Sedgewick algorithm books are good. The Algorithm Design Manual by Skiena is good as well. Together these books follow me on every bookshelf at every job I go to, along with The Mythical Man-Month.

Talk to people you respect. Ask them what decision points they had and why they made the decisions they did. The good ones will always be able to tell you "I chose to do X because it's better than A, B in these ways. I could have gone with C, but I felt this was a better choice because of this".

Next, do.

Build stuff. Build stuff that you'll never use. Build stuff that you'll never need. Go write a program that solves a Sudoku puzzle. Now go do it again. And again. Build it 5 completely different ways. Build a program that generates Sudoku puzzles and feed it into the solvers. Find which solver is fastest. And then...

Find out why.

The "what" is almost never important. I mean, yeah, it is critical to finishing the project at hand, but at the end if you know the "what" without knowing the "why", then you might as well never done it in the first place. You got a bullet point on your resume. Go get a cookie and congratulate yourself. The "why" is so much more important than the "what".

And for the record Sudoku was an example. I spent a lot of free time going through that exercise with a ton of the logic puzzles on Kongregate and learned a lot on the way.

• really really good answer! I like the way you phrased your advice! Commented Aug 26, 2012 at 10:13
• I also take Sedgewick and Skienna books with me everywhere! that's probably another reason why I loved your answer! Commented Aug 26, 2012 at 10:13
• and Cormen to the mix please. Commented Feb 9, 2013 at 8:01
• In the age of an ever-increasing drive to information on the internet, it's important to add: read books (not exclusively, of course). A consistent, coherent introduction into a matter that's longer than 2-3 ad-separated HTML pages is A Good Thing™! Don't underestimate it (and yes, of course ebooks are fine). Commented Apr 8, 2013 at 16:29
• Agreed. Consistency is key. It's hard to grok data structures when you're getting one or two from a dozen different sources. Books also tend to have better diagrams (some blogs/online sources do, but as a generalization books are better). The Sedgewick books have a particularly good mix of diagrams, simple to follow code and description. Commented Apr 8, 2013 at 20:46

### Algorithms

I took magic lessons in a group setting when I was twelve years old. The magician's name was Joe Carota. He did a trick one time and I blurted out, "How did you do that?" He said something that day that has stuck with me ever since.

Joe's response, "Michael, if you really want to know how that trick is done you must figure out how you would do it yourself."

Well of course that's not what I wanted to hear but it did get my mind focused on problem solving. This was problem solving from my perspective. If my first attempt at solving the problem took seventeen steps and was really klunky, the good news was I solved the problem.

Then by looking at the solution I had developed and looking for ways to refine that solution I would learn how to streamline the end result. Later on in my computer programming life I found out that this process was called "Stepwise Refinement". I think today they call it refactoring.

It worked then it still works now.

here the following link redirects you to one of the most successful DS and Algorithms classes by MIT I've ever followed.

Hope you'll enjoy this video series. Good luck !!!

See if you can take an online course, or get tutored. Failing that, this popped up in a quick google search. I just took a class on it this past spring (first ever, I moved from EE to software) and it wasn't too hard to pick up if you understand pointers well.

If you aren't able to take a course on this, I'd recommend The Algorithm Design Manual. There's a free PDF here, but it's worth getting the actual book if you plan on programming professionally.

Try to enroll in an undergraduate level course in data structures and algorithms, it's always good to learn these concepts along side others.

• I am a graduate from computer science and it has been six years since then. I never concentrated on these subject there it was web, usability, client server, that attracted me and i am working on these fields only but now i feel like i should learn them as well. What are your thoughts. Commented Nov 12, 2010 at 17:10
• Go back and take a refresher course :-) Commented Nov 12, 2010 at 18:27

Start working on solving classical problems on for example sphere online, the site might not look that fancy but boy, these are classical programming problems that require many of the important data structures and algorithms in use today.

Solutions can be submitted in a variety of programming languages from C/C++ to JavaScript, Lisp, Smalltalk, assembler + some 40 more. So you can focus entirely on solving the problem with whatever programming language you feel comfortable with.

This is by far my favorite resource. I used it in my undergraduate computer science algorithms course and ended up buying the book 4 years later to read on my own to prepare for my M.S. Comp Sci courses. It isn't an easy read by any means but if you work to understand the some of the math/proofs presented and then implement the pseudo-code in your favorite language(s), it is well worth the somewhat hefty price-tag. The Algorithm Design Manual others have mentioned is also a great resource for learning problem identification but I found CLRS to be better for pure detail.

You could always try something like this: http://codekata.pragprog.com/

I always learned better by thinking it out as opposed to reading. However, you should have documentation/reading material available to look for answers.

Buy this book, Loan this or Steal this! Rest will follow :)

Introduction to Algorithms by Rivest and Cormen. It will be very hard to follow initially once you get past the explanation of the Mergesort in the introduction. Everything unfolds to you beautifully.

Plus you will get more better if you solve the problems given in the book. I never really wanted to part with the book even after graduating from grad school. It's that good.