Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I usually do well at figuring out solutions to programming assignments but for some reason, I'm really struggling in my Algorithms class. I'm not failing but I know I can do better.

When I'm confronted with problems like "Divide the array to 2 subarrays so that the sum of each subarray is equal to the other subarray," I feel like my brain won't cooperate and think and I end up not being able to solve it.

Some of the things I'm doing right now to help myself:

  • reading CLR (1st ed.) -- it takes a lot of time for stuff to sink in and I can't understand most of it
  • solving some problems -- no matter how much I try, most of the time, I end up googling for the solution before I understand how to solve it

I know that good algorithmic skills are very important because lots of good companies ask these sorts of questions in their interview process so I'm a bit worried right now.

What else can can I do to improve my algorithmic/problem solving skills? Any advice on how to deal with this?

share|improve this question
5  
The example you gave is an NP-Hard problem. Even the best algorithm experts of today have trouble getting efficient algorithms for that! – Moron Feb 23 '11 at 17:39
@Moron It didn't have to be efficient as long as you have a correct algorithm so brute force would've been acceptable for that question. – David Burr Feb 23 '11 at 17:43
@David: I see. I agree with jwir3 and MAK and have voted to move this question to programmers. – Moron Feb 23 '11 at 17:46
3  
The CLR book is not light read, but it is still a decent book. Don't feel bad if you have to re-read some sections 2, 3, 4 or more times. I know I did that. Sometimes it's best to skim a section just to get a feel for it, then re-read it in depth. If it's still hard, walk away and come back to it in a day or so (once you're brain has had some time to digest the new information). Might be on the second or third (or nth) reading that it all just clicks into place. – FrustratedWithFormsDesigner Feb 23 '11 at 17:53
The algorithm design manual is pretty easy to understand – Anto Feb 23 '11 at 18:01
show 1 more comment

migrated from stackoverflow.com Feb 23 '11 at 17:48

9 Answers

Ask a {professor, tutor, friend} for help. Learning isn't done in a vacuum. Try to formalize what is confusing you about the problem so that you can explain to your helper what you are struggling with.

I used to think about algorithms in terms of a specific programming language. That really hampered how I viewed the problem (and hence, the solution).

These things just take practice. You are not stupid, you're just climbing the learning curve (which is really tough).

share|improve this answer
+1, good suggestion. Besides which, half the time when you explain what you don't understand, sometime through explaining it the penny drops and you understand. – DominicMcDonnell Feb 23 '11 at 20:49

Introduction to Algorithms -- I really wonder how many people who didn't understand algorithms actually gain something by reading that book. Not that because it is bad, but because it is not for beginners.

A good introductory book for algorithms is Algorithm Design Manual by Steven S. Skiena. Try it out!

share|improve this answer
+1 Very good book indeed – Anto Feb 23 '11 at 20:10
And actually readable - also includes bedtime stories – Martin Beckett Feb 25 '11 at 6:07

CLR is a bit much to take in. see this question for other suggested materials.

You need to learn the basic techniques, mainly because all this stuff has already been solved - you just have to recognise which 'classic' solution this is the same as.

share|improve this answer

Check out the Euler Project. It contains several hundreds different, but focused, programming problems. Solutions here and some code here.

share|improve this answer

Read "An introduction to Algorithms" by Thomas H. Cormen.

And solve problems from USACO (google it). From the simplest ones. To the harder ones.

share|improve this answer
4  
That is the CLR that the poster says they couldn't follow – Martin Beckett Feb 23 '11 at 17:45
1  
"CLR" == "Cormen, Leiserson, Rivest" == "Introduction to Algorithms" :-) I definitely agree that it should be read, though. – Aasmund Eldhuset Feb 23 '11 at 17:48
Take it as an encouragement :D – Andrei Duma Feb 23 '11 at 18:42

If you're fluent in C/C++, I would highly recommend Bentley's "Programming Pearls" despite its age.

It's not a textbook or an interview prep book - more of a collection of articles, but it's effective at making you think algorithmically and in terms of gotchas.

share|improve this answer

Like everything else, practice, practice, practice, practice, and practice more.

Introduction to Algorithms is a massive book and can be difficult to read. But it is probably the best book available on the subject. Go through it slowly, and repeatedly.

share|improve this answer

A bit of lateral thinking, but try reading some Raymond Smullyan books. "What Is the Name of This Book?" and ""The Lady or the Tiger?" are particularly good.

While neither of them will teach you algorithms, they might teach you how to switch your brain into the problem-solving mode that is required to deal with algorithms.

share|improve this answer

Have you ever thought about what kinds of strategies you know for generating an algorithm? To give a few examples:

Design patterns can also be useful sometimes for solving a problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.