This post is a review (or possibly some long winded rambling) of the book Essential Algorithms: A Practical Approach to Computer Algorithms by Rod Stephens and published by Wiley.
Disclaimer: I received a copy of this book (with a personal signed inscription too :)) directly from Rod with the condition that I review the book. This has not influenced my review except that I have tried to do a decent job rather than just picking a star and saying I liked it.
The book has quite a few chapters covering a pretty good selection of algorithms, including
- Numerical Algorithms
- Linked Lists, Arrays, Stacks and Queues, Hash Tables
- Trees, Balanced Trees, Decision Trees
- Basic Network Algorithms, More Network Algorithms
- String Algorithms
- Complexity Theory
- Distributed Algorithms
There's also a glossary as you would expect with this sort of reference, and an appendix with the answers to all the practice questions - you will need this!
Each chapter is divided into sections, and ends with a summary
and a set of practice questions, some of which are marked with
one or more
* to indicate a tougher problems. Standard stuff!
There's also sample code available from the book's website.
Tell me about the book already
I don't have a very strong maths background, and there is a distinct lack of material on either mathematics or algorithms to be found in my selection of programming books. I do have one other book on the subject of algorithms/data structures - it is so dry and filled with source code in an unfamiliar language I haven't even attempted to read it yet.
Essential Algorithms on the other hand, is a book I found to be very approachable, bar a hiccup or two.
When I buy computer books, they are pretty much always for a specific language or technology, but I think Essential Algorithms is actually language agnostic. While the accompanying downloadable source is in C#, the code in the book is pseudo code written as plain English (or perhaps Rod's version of Beginners All-purpose Symbo... cough). I actually found this refreshing as when trying to grasp a tenet of the algorithms Rod was describing I didn't have to "think code" which is more helpful than it sounds.
So I mentioned hiccups. What were these? Well, my initial foray into the book was slightly bewildering. The very first chapter, describes various performance characteristics (Big O notation) and chapter two dives right into numerical algorithms. This second chapter actually covers quite a lot, but I did find it difficult to grasp. I don't find fault with Rod's writing for this, but my lack of knowledge on mathematics. With that said, it looked interesting enough that I am determined to get enough knowledge to be able to read this chapter and understand it!
When is an algorithm not an algorithm
Chapters three through five cover linked lists, arrays, stacks and queues, something I suspect any C# developer would recognise. Even though I'm intimately familiar with these data structures, and, (with the exception of linked lists) use them regularly, I still discovered quite a few new things I hadn't considered regarding implementation and advanced usage of such structures, which never occurred to me when using black box implementations.
An example of this is sentinel values to avoid having to write code to handle special cases (such as the start or end of a linked list). Seems obvious but I hadn't thought of it - assuming I was aware of the special case I'd write extra code to handle it.
Sorting and Searching
I suppose every programmer can write a bubble sort without even thinking about it, but Essential Algorithms covers no less than 8 different ways of performing a sort.
Closely tied to sorting is searching, as it is more efficient to search sorted data. Oddly however, this is an incredibly short chapter - barely 6 pages. However, it does include binary and interpolation search algorithms which are much better than the usual linear search that I would normally do.
With that said, the book then follows on with a detailed chapter on hash tables which can also help you find data extremely fast.
Seeing the forest for the trees
Many people are familiar with a tree as a means of presenting hierarchical data, but that's not what the chapters on trees cover. Essential Algorithms describes binary trees, complete trees, sorted trees, how to traverse trees, how to search trees, expression evaluation, the list goes on.
I found this chapter engrossing as I could dimly see the light bulb flickering of how I could make use of these techniques.
This is then followed by a chapter on balanced trees (AVL trees and b-trees). I started getting a bit lost here, although it didn't help due to my schedule I was reading through the last chapters very piecemeal, a few pages here, a page or two there. While I started to get glimmers of ideas from the first two chapters on trees, the 3rd tree chapter - Decision Trees - was another head scratcher.
Networks are trees with added epic
There are two chapters which deal with networks. As with the first couple of tree chapters, I also found these chapters quite interesting, with the caveat I couldn't immediately see how I can use this knowledge in my code. They cover network traversal, short path detection, map colouring (whoever would believe that automatically colouring a map in as few shades as possible would be so hard!) and a bit more besides.
My head is hurting again
The last few chapters deal with cryptology (interesting, but there's no way I'm going to try reinventing that wheel, I'll use managed black box classes!), complexity theory (I gave up trying to understand it) and distributed algorithms, which falls neatly under the parallel processing banner and so again should be somewhat familiar to C# developers. I wondered why this was the last chapter as the complexity theory was so complicated it should have been at the end.
I haven't tried most of the exercises offered at the end of each chapter, so I can't comment on the accuracy of these. And, as I haven't finished them I've avoided looking in detail at the source code examples. The ones I have browsed don't seem to be bad, and while are not extensively commented (so you'll probably have to have the book to hand for reference), they do include enough comments for you to know what's going on, and the code itself is not written in an obtuse fashion. Even from the brief look I'd taken I could see things I could learn from so yet more bonus.
Unlike many programming books I have bought in the past, Essential Algorithms is actually a book that I want to read again, both to pick up what eluded me the first time around, and to help me visualize ways of using what I have learned in the code I write.
However, if like me you don't have a strong head for maths, you might struggle with some of the chapters.
- 2015-03-07 - First published
- 2020-11-21 - Updated formatting