# Is there a canonical reference on algorithm design?

So every time I get an interview, I get simple problems. The problem is, I seem to make a mess of it by writing inefficient algorithms that either take too much space or time. I am really not able to break down a problem into smaller parts and solve it using algorithms I would have used before.

Is there a reference (book or website) that describes the best practices and approaches of algorithm design? What about that resource makes it special?

-
What is your background? If you have a computer science or math degree then CLRS or similar books would be fine. Otherwise an lightweight introduction to algorithms would be good. – lasseespeholt Apr 20 '11 at 16:14
@lasseespeholt: i have a computer science degree – yahh Apr 20 '11 at 16:15
@yahh Okay, then CLRS could be good to read. And supplement it with ProjectEuler and pages with more diverse exercises so you learn to use them. – lasseespeholt Apr 20 '11 at 16:19
Brute force isn't a bad place to start, as it gives you a reference to compare your algorithm with both for performance and correctness. – hammar Apr 20 '11 at 16:19
You have a CS degree or are pursuing a degree? Because not to be bearer of bad news but a CS degree should include algorithm design topics. Not saying you should be able to on a whim implement dijkstra's algorithm but you should understand basic loop complexities various search algorithms. – Chris Apr 20 '11 at 17:39

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer: please explain why you're recommending it as a solution. Answers that don't explain anything will be deleted. See Good Subjective, Bad Subjective for more information.

## migrated from stackoverflow.comApr 20 '11 at 16:52

Getting the basics right is always good! Plus more Practice !

-
you should practice the solutions. even if it takes a lot of time to understand an algorithm, the thinking process will help you to solve apparently unrelated problems – titus Apr 20 '11 at 16:50
@Morpheus:i have already read this book – yahh Apr 20 '11 at 16:50
@yahh It's the best book i read so far on algorithms, like titus said it takes a while to understand which algorithm to use when! – Morpheus Apr 20 '11 at 17:04
Add the word practice and you'll have my +1. Practice practice practice. – PeterAllenWebb Apr 20 '11 at 17:22
@yahh: read, or read and did the exercises? The difference is important. – Мסž Apr 21 '11 at 0:48

These online judges might be of help for practicing algorithmic problems

-
 These links are awesome! More programmers should know about these... – gsingh2011 Oct 12 '11 at 23:49 would you mind expanding a bit on what each of these resources have and why do you recommend these as answering the question asked? "Link-only answers" are not quite welcome at Stack Exchange – gnat Apr 14 at 7:35

Getting simple problems right is basically a matter of lots of practice. Take a look at Cracking the Coding Interview by Gayle Laakman Mcdowell. I've found it to be a really useful resource for training on algorithms differently. Also check out the site CareerCup for a variety of interview questions. You could also benefit from competing in TopCoder.

-

Work your way through TopCoder Algorithms Tutorials and you'll gain a familiarity with a lot of the kinds of problems that get asked on interviews. (Simple to state. Tricky to solve. But doable within an interval.)

-

Programming Challenges by Steven S. Skiena and Miguel Revilla is a pretty good book for practising this sort of thing.

-
 would you mind explaining more on what it does and what it's good for? "Link-only answers" are not quite welcome at Stack Exchange – gnat Apr 14 at 7:34

I learnt most of the coolest algorithms from internet only. I guess a good staring point is CLRS. You can also try these:

Personally I Algorithm Design to be a very good book but CLRS is an encyclopedia.

-

Yes, as others have said: brute force and naive is a perfectly good start. Working is better than non-working.

After that, consider and optimize. Sometimes you'll need to try a completely different approach (good luck with that), and sometimes it's just plain hard.

There's really not that much algorithmic sophistication in the real world (at least, the part of it that I live in), so those interview questions are kind of BS.

-

As @hammar said, brute force is a good place to start. In general, what sort of unlocked the subject for me was thinking in terms of information flow. To me, that makes it easy to classify algorithms and suggests how to make up new ones.

-