Algorithms in a Nutshell

A Desktop Quick Reference
Before Picking an Algorithm Know What Problem You’re Trying to Solve.

Algorithms in a Nutshell is a book aimed at programmers who need practical examples of how to use them to solve problems in their software. As the authors say right in the beginning, they didn’t want to write a book that was either too abstract or too focused on solving a particular problem. As they put it, the problem with the former is that, except for the simplest examples, the pseudo-code doesn’t provide enough help turning that into actual working code. While the later is often too closely tied to the problem being demonstrated, so the coder has to figure out how to separate the general algorithm from the specific example. Instead, the approach they took is to teach the reader to figure out what they need, what algorithms are available to solve problems, and what to do when there isn’t an apparent solution possible.

Finding what you need in the first place is a critical step. It’s addressed in several parts of the book. Chapter 11, for instance, mentions the principle “know your data”, that pretty much sums up the idea that you have to know what you want to accomplish before picking a specific algorithm. As an example, the sorting chapter shows several different algorithms. It points out cases, where the simpler to write ones (i.e. potentially fewer bugs to hunt down), might be fine for a situation as long as the data set isn’t too large. Once you know how to define what you are looking for, the next step is finding the tool to solve it.

See also  Mining the Social Web

The middle section covers about 35 different algorithms in the areas of sorting, searching, graph algorithms, path-finding, network flow algorithms and computational geometry. Each algorithm is explained along with some variations and optimizations that are commonly done. One interesting feature of the book is the fact-sheets that provide a graphical overview of the algorithm being discussed, including some pseudo-code. O-notation and some performance and implementation notes, e.g. brute-force (these icons are explained on pages 41-43) that give a quick overview of the algorithm being discussed.

Finally, the book discusses what to do when there isn’t an apparent solution. The advice given is to do two things: figure out what you are trying to solve (“know your data”) and break your problem down into smaller, solvable problems.

It took me a bit of time to find the source code mentioned in the book. Eventually found it in the “Releases” folder along with code from an O’Reilly blog on algorithms by the same authors- That which also explained the meaning of the name (ADK: Algorithms Development Kit) used for the source code. The code is provided in various languages, mostly C/C++ and Java, with some Ruby in places, mainly as a comparison. The book’s layout reminds me a bit of the “Hacks” series of books. It’s a small format, about 350 pages black/white/grey design. I’d recommend this book as a useful reference.