Recently I read the book “Grokking Algorithms: An illustrative guide for programmers and other curious people” by Aditya Y. Bargava and published by Manning in 2016. I never read a book before checking the inside cover to see the print edition, year and publisher. The year isn’t overly critical for an introductory book into algorithms, especially one that doesn’t focus heavily on implementation. However the publisher is always important and Manning Publications delivers top quality technical reads which was the first reason I decided the book might be worth my while.

The second reason I peeked into “Grokking Algorithms: An Illustrated Guide…” was that my brain hurt, I had been working long hours writing code and felt spending more hours reading code for recreation wouldn’t be beneficial. I’d wanted to learn something useful with wide applications, reasonably new to me, challenging enough to hold my interest while also being quickly picked up and easily put down without requiring too much prerequisite knowledge. *I’m demanding of my books as you too should be*. I saw “Grokking Algorithms: An Illustrated Guide…” and I grabbed it with the intention of jumping to a chapter from the latter half of the book, maybe bouncing around a bit and taking in some cute illustrations. I had assumed it wouldn’t hold much more value aside from entertaining me while offering glimpses into future topics which might lead to books meeting the reading requirements above and filling time until I found that better read. I didn’t think the phrase “a picture is worth a thousand words” would hold true with illustrations in a technical book. I stand here now corrected, my assumptions all erroneous and having been withdrawn.

Whether you have been programming for a few years or a few days, or maybe as the title implies your just a “curious person”, there’s value to take away from reading this book. Aditya Bhargava is great at explaining the complexities of computer science and problem solving in a unique, easy to consume and most importantly, a meaningful way. The book doesn’t hand you a drop in implementation for each algorithm, nor does it offer any magical solutions. Rather, using simple illustrations and step by step instruction, “Grokking Algorithms: a.i.g.f.p.a.o.c.p.” imprints upon the reader many brilliant mental models to apply into their own projects along with contextual clues to recognize in the future while faced with pairing up real world problems with their appropriate solutions. In the end, an algorithm is just a solution that when understood becomes a tool for shaping the execution and flow of code and data to meet the demands of our applications.

Normally, I’ll read from the beginning of a book and work through linearly, even if I believe the material to already be part of my skillset. I find different authors shine their lights into the darkness at different angles; in doing so they bring clarity to certain aspects of a topic while casting shadow over others (it’s this relationship that varies a tutorial/guide from a document/reference). There is always something new brought to attention when having something taught to us under different teachers. However, since I hadn’t planned on reading this book though, I skipped ahead to the 9th chapter titled “Dynamic Programming”. I wasn’t very familiar with the concept of dynamic programming, so in the worst case I would at least have another geek term to add to my repertoire.

I was so impressed with how much information Bhargava was able to present in a single chapter. It opened up shortly into the “knapsack problem”, a problem older than you and I. If you are unfamiliar with the knapsack problem, it basically states that there is a knapsack (*backpack*) that can hold `n`

units and there are “things” which we want to fit into the knapsack; each “thing” has a `value`

as well as a unit `size`

, so the question is, what combination of “things” can we fit into this knapsack yielding the greatest `value`

? The `units`

can be anything quantitative such as size or weight and the value could be any other type of measurement, for the knapsack problem it is usually represented by size and currency. You may have heard of this problem being called the “bandit with a knapsack” problem.

Bhargava offers up the simple solution first, the one that any programmer or curious person faced with this problem, and not yet familiar with the knapsack conundrum, might immediately jump to using (*trying all possible combinations of items*). Then he explains the downside to that immediate solution, namely exponential computation for any additional “things” introduced to the problem. So then rather than simply stating “That bad. This good”, Aditya references material from past chapters and takes the reader into the thought process of the problem solver, starting to break down the problem into smaller, easier to consume parts.

Now, the idea behind dynamic programming is breaking a large difficult problem into smaller easy problems and in the process of solving for those simple problems we find an answer for the bigger problem. However, when I say that Aditya breaks down the problem into smaller, easier to consume parts, I don’t just mean for the sake of explaining dynamic programming. The entire book he makes these problems feel easy to the reader. At the end of each chapter you will feel as if you are ready to go out yourself and teach someone else how to use the techniques you were just introduced to. The transition from just being curious to actually understanding the application of dynamic programming (and every other concept in the book) is so smooth that the reader doesn’t only enjoy what they learned but also how they learned it.

You might think, well I don’t write programs to sort backpacks so I don’t think I need to read this. But maybe your website is a backpack, the units of space are pixels, the “things” are advertisements and the value we’re maximizing is “revenue”. One of the cooler and more subtle techniques used by Bhargava in “Grokking Algorithms: An Illustrated Guide…” to teach the reader is the way he explains how one might recognize and classify the type of problem they are facing so in the reader’s day to day work they might better see the connection between their problem and the problems used in the book. If the reader can say “oh this is like the knapsack problem”, then the reader can also say “I know how to solve this problem” or at least “I know where to find a blueprint for solving this problem”. The connections to daily problems aren’t always apparent until after they are worked out.

I wound up reading the previous chapter on “Greedy algorithms”, because it was referenced from the chapter on “Dynamic programming”. Then I jumped back a few more chapters to another reference by the author within the book, and another, until finally I just read the book from start to finish. I even found myself taking notes at times because the material felt so understandable that taking a few pages of notes would help me to more easily remember certain concepts in the future.

## Conclusion

“Grokking Algorithms: An Illustrated Guide…” is smooth ride over difficult terrain. While it does dive into complex topics, Bhargava never leaves the reader feeling in over their depth. I have to give great credit to the author because when someone can make topics such as these seem simple for almost anyone to comprehend it is no small feat. If you’re curious to learn algorithms or already know a few and just want to learn more, this is a great book and will hold your interest.

“Grokking Algorithms: An Illustrated Guide…” has enough value to warrant keeping it around the office. I would even say that you should keep it somewhere where other people would see it as they walk by your desk so that those other programmers and curious people will have the opportunity to flip through this fantastic book as well.

My favorite chapters in this book were **7** and **9**, “**Dijkstra’s Algorithm**“ and “**K-Nearest neighbor**“. Illustrations have gone hand in hand with problems involving graphs for a very long time as that is how data in graphs is most easily related to us, through visualisations. Although *K-nearest neighbor* quickly becomes impossible to draw out (*or even picture mentally as it is an algorithm solving for distance between points graphed along n-dimensions*), *Dijkstra’s algorithm* on the other hand is described well visually from start to finish as it works with DAGs (directed acyclic graphs) which are two dimensional, directional graphs, like the ones teacher used to draw on the chalkboard.

Dijkstra’s algorithm solves for shortest distance from V_{1} to V_{n} and is easily shown in illustration. There is probably no easier way of following directional edges from a source node while comparing the weighted edges between nodes than by using a visual aid (*See how confusing it sounds with my words?*). Combine these *facts* with Aditya’s talent at stepping through problems using illustrations and it’s a winning combination that anyone will clearly grok. That being said, my words end here; Manning offers free sample content by Aditya Bhargava explaining Dijkstras Algorithm which is based on the content from chapter 7 in the book. The sample content skips the introduction to the algorithm, nonetheless, it demonstrates the power in the information you will hold when you purchase a copy of “Grokking Algorithms: An Illustrative Guide for Programmers and Other Curious People”.

Title | “Grokking Algorithms: An illustrative guide for programmers and other curious people” |

Author | Aditya Y. Bargava |

Publisher | Manning Publications Co |

Year | 2016 |

ISBN | 9781617292231 |