Another book on algorithms?
I recently read "Grokking Algorithms" by Aditya Bhargava[1] and my initial reaction was "does the world really need another book on algorithms?" I was soon won over by the light yet accurate style and ended up really enjoying it. It is pitched at the beginner (or beginner's mind) and I think he's hit on a gap in the current market especially when it comes to shorter texts that enlighten and entertain. It's lucid and doesn't get bogged down in programming language details. He happens to use Python, but it's almost incidental. I'm not a fan of algorithms books using a programming language for reasons I'll go into further on. It got me thinking about the algorithms books I already possess, so I spent a bit of time skimming in order to form an opinion on what I like about them. So here is a list of the texts I've read, or partially read, to be completely candid; I have not read any cover to cover, but have studied enough of each to feel entitled to have an opinion about them.
Introduction to Algorithms, by Cormen et al (aka CLRS)[2]. For comprehensiveness and theoretical rigor this is hard to beat. It gives the most in-depth treatment of how to prove algorithm correctness, and if you're interested in academic rigor this is probably the best on the list. However, if you're coming from a practitioner's standpoint it can be a little daunting, and perhaps overkill. For example, the chapter on np-completeness starts by laying out a formal model for discussing the topic at hand, giving you an unexpected preamble to get to grips with before getting to np-completeness. Yes, it may be the most comprehensive treatment of the subject, but if you're feeling pressed for time this one can feel a bit like disappearing down a rabbit hole.
Algorithms, by Papadimitriou et al. Probably my personal favourite, this strikes a good balance between academic rigor and practical application. It's a shining example of communicating a technical subject using a mix of concise formalism and plain language. Case in point: the knapsack algorithm with and without repetitions is covered in under two pages in a manner that conveys the essence of the algorithm, and its variants, in a crystal clear manner. Impressive for a non-trivial algorithm. For balance between clarity and conciseness this is hard to beat. It's the one I try to emulate whenever I have to explain or document something.
Algorithms, by Sedgewick & Wayne.[3] Another one that gets a nice balance between academic rigor and implementation concerns. On the minus side, it's the only book on the list that uses a programming language (Java), and while I've nothing against Java (or nothing that I won't go into here) I prefer to see a notation such as predicate calculus[4a] or TLA[4] being used for a couple of reasons: with a programming language you occasionally need to reason about the minutiae of the language, warts and all. In addition, you're being spoon-fed an end to end solution, and in my experience it leads to better understanding to implement an algorithm from a declarative specification rather than work backwards through code. But the authors take a nice API-first approach and steer clear of the more idiosyncratic features of Java, so this is a minor complaint. It is such a good book regardless.
The Algorithm Design Manual, by Skiena.[5] This is a great compendium, and is the one most aimed at the practitioner of all the texts on this list. There are "war stories" in each section that relate the topic at hand to real life applications, mostly drawn from the author's experience. In terms of breadth it probably covers, or at least references, more algorithms than any other text in this list. On the minus side many of the references use URLs and are obsolete thanks to the vagaries of internet time. In this respect it's probably the text that could most do with an overhaul, although it is particularly challenging to keep references to URLs up to date. Overall this is a minor point, I like the author's writing style and reach for this for insights into the variations of, or examples of the applications of, certain algorithms.
Algorithm Design, by Kleinberg and Tardos.[6] The one on the list I'm least familiar with, but I really like clarity of the writing in the parts I've studied. Algorithms are explained comprehensively, yet in a manner that is more digestible than say CLRS (to me anyway). It helps that the presentation of each algorithm topic is structured in three clear stages: problem statement, algorithm design and algorithm implementation, guiding you through the conceptual, logical and physical levels in a structured way. It recently gave me a valuable insight into the spectrum of scheduling problems, in particular how some stray into NP-complete territory. I think this is one I might be spending more time with in future.
Whatever about a "favorite" or "best", there's one thing that all these writers need to contend with, and that's change. It may be stating the obvious to say that algorithms are a dynamic and evolving field, but when you pick up a book (or five) you may subconsciously think it's all "solved problems", permanently fixed in ink for you to refer to in perpetuity. But there are always improvements to existing algorithms being made and new algorithms being created. Consequently, a text book may lag the state of the art often by several years (or decades in some cases). For example, you won't find Ukonen's algorithm[7] for building a suffix tree in linear time in any of the aforementioned publications. It, and other algorithms on strings, have been put to extensive use in biotech [8], a great example of how intense research in a subject - DNA sequencing in particular - forces the field to create new and better algorithms. New inventions and improvements do make their way into the standard texts; Robert Sedgewick published an improvement to insertions and deletions of red-black trees[13], a discovery that made it into the 4th edition of his book. So it pays to keep an eye on what's new in the new editions. Given that we're firmly in the era of many-core architectures, perhaps work in the parallelization of or making algorithms cache friendlier[14][15a,15b] will make its way into the standard texts. Thanks largely to "big data", there's been extensive adoption of probabilistic algorithms [9][10][11] in the last few years, and increasing volumes of data has spawned an increasingly enthusiastic adoption of Machine Learning algorithms[12], so one could also speculate that these topics will see more coverage in future editions. All bearing in mind that the biggest challenge these authors face is probably deciding what to leave out...
Circling back to the list, I'm going to sit on the fence when it comes to a favorite, and reach for that well worn cliche "it depends", but it depends fundamentally on where you're coming from; if you need a rigorous, academic approach and want to learn about proof and correctness then CLRS is hard to beat. If you're coming from a professional practitioner's standpoint then Papadimitriou or Skiena will probably get you going more expeditiously. And, if your approach is beginner's mind, one I like to adopt because I like to approach problems from first principles, then Sedgwick is a good one. If you're stuck in a problem and are looking for insights or variations on a theme, Skiena might provide the necessary direction. If I had to pick one, it would be Papadimitirou, for the clear and succinct exposition. But the tl;dr is that it pays to have a few within reach, and different perspectives go a long way.
In conclusion, I'll briefly acknowledge there are some classic texts I have yet to read in any depth[16][17]. Some day...
Introduction to Algorithms, by Cormen et al (aka CLRS)[2]. For comprehensiveness and theoretical rigor this is hard to beat. It gives the most in-depth treatment of how to prove algorithm correctness, and if you're interested in academic rigor this is probably the best on the list. However, if you're coming from a practitioner's standpoint it can be a little daunting, and perhaps overkill. For example, the chapter on np-completeness starts by laying out a formal model for discussing the topic at hand, giving you an unexpected preamble to get to grips with before getting to np-completeness. Yes, it may be the most comprehensive treatment of the subject, but if you're feeling pressed for time this one can feel a bit like disappearing down a rabbit hole.
Algorithms, by Papadimitriou et al. Probably my personal favourite, this strikes a good balance between academic rigor and practical application. It's a shining example of communicating a technical subject using a mix of concise formalism and plain language. Case in point: the knapsack algorithm with and without repetitions is covered in under two pages in a manner that conveys the essence of the algorithm, and its variants, in a crystal clear manner. Impressive for a non-trivial algorithm. For balance between clarity and conciseness this is hard to beat. It's the one I try to emulate whenever I have to explain or document something.
Algorithms, by Sedgewick & Wayne.[3] Another one that gets a nice balance between academic rigor and implementation concerns. On the minus side, it's the only book on the list that uses a programming language (Java), and while I've nothing against Java (or nothing that I won't go into here) I prefer to see a notation such as predicate calculus[4a] or TLA[4] being used for a couple of reasons: with a programming language you occasionally need to reason about the minutiae of the language, warts and all. In addition, you're being spoon-fed an end to end solution, and in my experience it leads to better understanding to implement an algorithm from a declarative specification rather than work backwards through code. But the authors take a nice API-first approach and steer clear of the more idiosyncratic features of Java, so this is a minor complaint. It is such a good book regardless.
The Algorithm Design Manual, by Skiena.[5] This is a great compendium, and is the one most aimed at the practitioner of all the texts on this list. There are "war stories" in each section that relate the topic at hand to real life applications, mostly drawn from the author's experience. In terms of breadth it probably covers, or at least references, more algorithms than any other text in this list. On the minus side many of the references use URLs and are obsolete thanks to the vagaries of internet time. In this respect it's probably the text that could most do with an overhaul, although it is particularly challenging to keep references to URLs up to date. Overall this is a minor point, I like the author's writing style and reach for this for insights into the variations of, or examples of the applications of, certain algorithms.
Algorithm Design, by Kleinberg and Tardos.[6] The one on the list I'm least familiar with, but I really like clarity of the writing in the parts I've studied. Algorithms are explained comprehensively, yet in a manner that is more digestible than say CLRS (to me anyway). It helps that the presentation of each algorithm topic is structured in three clear stages: problem statement, algorithm design and algorithm implementation, guiding you through the conceptual, logical and physical levels in a structured way. It recently gave me a valuable insight into the spectrum of scheduling problems, in particular how some stray into NP-complete territory. I think this is one I might be spending more time with in future.
Whatever about a "favorite" or "best", there's one thing that all these writers need to contend with, and that's change. It may be stating the obvious to say that algorithms are a dynamic and evolving field, but when you pick up a book (or five) you may subconsciously think it's all "solved problems", permanently fixed in ink for you to refer to in perpetuity. But there are always improvements to existing algorithms being made and new algorithms being created. Consequently, a text book may lag the state of the art often by several years (or decades in some cases). For example, you won't find Ukonen's algorithm[7] for building a suffix tree in linear time in any of the aforementioned publications. It, and other algorithms on strings, have been put to extensive use in biotech [8], a great example of how intense research in a subject - DNA sequencing in particular - forces the field to create new and better algorithms. New inventions and improvements do make their way into the standard texts; Robert Sedgewick published an improvement to insertions and deletions of red-black trees[13], a discovery that made it into the 4th edition of his book. So it pays to keep an eye on what's new in the new editions. Given that we're firmly in the era of many-core architectures, perhaps work in the parallelization of or making algorithms cache friendlier[14][15a,15b] will make its way into the standard texts. Thanks largely to "big data", there's been extensive adoption of probabilistic algorithms [9][10][11] in the last few years, and increasing volumes of data has spawned an increasingly enthusiastic adoption of Machine Learning algorithms[12], so one could also speculate that these topics will see more coverage in future editions. All bearing in mind that the biggest challenge these authors face is probably deciding what to leave out...
Circling back to the list, I'm going to sit on the fence when it comes to a favorite, and reach for that well worn cliche "it depends", but it depends fundamentally on where you're coming from; if you need a rigorous, academic approach and want to learn about proof and correctness then CLRS is hard to beat. If you're coming from a professional practitioner's standpoint then Papadimitriou or Skiena will probably get you going more expeditiously. And, if your approach is beginner's mind, one I like to adopt because I like to approach problems from first principles, then Sedgwick is a good one. If you're stuck in a problem and are looking for insights or variations on a theme, Skiena might provide the necessary direction. If I had to pick one, it would be Papadimitirou, for the clear and succinct exposition. But the tl;dr is that it pays to have a few within reach, and different perspectives go a long way.
In conclusion, I'll briefly acknowledge there are some classic texts I have yet to read in any depth[16][17]. Some day...