Back to index
OtherTwo to three weeks of evenings·Around $30 to $50 depending on format and retailer

Grokking Algorithms, Second Edition

4.6

The best first algorithms book there is. Hand drawn illustrations and Python code make the ideas stick, and the second edition finally covers trees properly. Not a substitute for a rigorous course, and it does not pretend to be.

What We Liked

  • The illustrations do real explanatory work rather than decorating the page
  • Python examples are short, annotated and actually runnable
  • Second edition adds binary search trees, balanced trees and B-trees, which the first edition lacked
  • Chapter length and pacing are judged well for evening reading
  • Builds genuine intuition for big O notation instead of just teaching the notation

What Could Be Better

  • Not enough depth for a serious technical interview at a large company
  • Light on proofs and formal analysis, which you will eventually need
  • Practice problems are too few to build real fluency on their own
  • Python only, so readers in other languages must translate as they go
  • Barely touches concurrency, amortised analysis or advanced graph algorithms

Detailed review

There is a specific problem that this book solves better than anything else I know. Plenty of self taught developers, and plenty of formally trained ones, have a working but hazy understanding of algorithms. They know quicksort is fast, they can recite that binary search is logarithmic, and they could not explain to a colleague why either is true. Grokking Algorithms fixes that, and it does it in roughly two weeks of evening reading.

The mechanism is the illustrations. Aditya Bhargava draws by hand, and the drawings are not decoration. When he explains breadth first search, you see the queue filling and draining. When he explains dynamic programming, the grid fills in front of you.

This sounds like a small thing and it is the entire reason the book works. Algorithms are spatial and temporal ideas that textbooks render as recurrence relations, and for a large number of people the recurrence relation arrives after the intuition or not at all. Reversing that order is the whole trick. The code is Python, short, and annotated.

You can type it out in a few minutes and break it deliberately to see what happens. The coverage runs through binary search, selection sort, recursion, quicksort, hash tables, breadth first search, Dijkstra's algorithm, greedy algorithms, dynamic programming and k nearest neighbours. The second edition adds trees, which is the change that matters most: binary search trees, balanced trees and B-trees, plus updated Python 3 code throughout. The first edition's omission of trees was its one real weakness and it is now fixed.

Big O notation is handled particularly well. Most introductions teach the notation and leave the reader able to write O of n log n without any feel for what that means when the input triples. This book builds the feel first, using concrete numbers and comparisons, so the notation lands as a description of something you already understand. That is worth the cover price on its own.

Now the limits, and Bhargava is honest about them himself. This is not a rigorous algorithms text. Proofs are largely absent, formal analysis is light, and the treatment of complexity is intuitive rather than precise. If you need to reason about amortised analysis, prove a bound, or handle the harder graph algorithms, this book will not get you there.

It also will not get you through a demanding technical interview at a large technology company. The concepts are necessary and insufficient. Interviewers ask questions that require pattern recognition built from solving a few hundred problems, and this book contains perhaps a few dozen exercises. Read it to understand the ideas, then go and grind problems somewhere designed for that.

Coverage gaps are worth naming. Concurrency is essentially absent. Advanced graph algorithms beyond Dijkstra get little space. String algorithms are thin.

Amortised analysis barely appears. These are all reasonable omissions for an introductory book and they are all things you will need eventually. The Python only code will mildly annoy readers working in other languages, though the algorithms translate straightforwardly and the annotations carry most of the explanation. On why this appears on a site about AI courses.

Machine learning engineering is software engineering. Vector search is a nearest neighbour problem, embedding retrieval performance is a data structure question, and the difference between a pipeline that runs in an hour and one that runs in a day is often a choice of algorithm. Plenty of people arrive at AI work through a data science route that never covered this material properly, and it shows the first time they need to make something fast. This book is the shortest path to fixing that.

My four point six is close to the top of what I would give any introductory book. It loses a fraction for the thin practice material and the absence of formal grounding, both of which mean it must be a first book rather than the only one. As a first book it has no serious competition, and I have recommended it more often than anything else in this catalogue.

[ final ]

The verdict.

Buy this if algorithms have never clicked for you. Read it, then move to a harder book or a proper course and grind problems on a practice platform. As a first book it has no real competition.