Can you Grok it?
Grok /ɡräk/- understand (something) intuitively or by empathy.
I came across a post recently on DEV.TO regarding why we should stop learning and focusing on frameworks so much. This is in many ways what I want this blog to be about. You can find the post on dev.to or on Eduards Sizovs blog here. In that spirit, I wanted to do a review of a book that helped me out with a subject that caused me a lot of consternation and difficulty when learning. That book is
Grokking Algorithms - An Illustrated Guide for programmers and other curious people by Aditya Y. Bhargava, and the subject is you guessed it – Algorithms.
Where to Begin
If you are a self-taught developer you are going to need to know something about algorithms. At least the common ones and why they matter. The reason being is that they can have real-world implications and even though computer processing power has come a long way, that is not always enough to overcome a problem when finding a more elegant solution using an appropriate algorithm will. This is where
Grokking Algorithms can help you to understand the basics.
Did I mention that the book had plenty of visuals and descriptions to help you understand the concepts along the way? In my opinion, this is extremely helpful and keeps the subject matter interesting and there was not one part in the book that felt like a text-book. There are also plenty of working examples. The book is geared towards any and all interested in grokking algorithms. Whether you be involved with software development or not, I can’t recommend this book enough.
The book starts off with a primer to algorithms and using binary search as an example. Don’t worry if this sounds complicated. Aditya does a great job of breaking the information down in such a way with examples that information is fairly easy to grasp and extrapolate. From there he moves into Big-O notation, now that we have a basic understanding of logarithms (or in my case a nice refressher). Big-O is easy enough to understand when you have an understanding of logarithmic relationships /linear relationships. The
O(n) is really just the number of computations to find a solution or how fast an algorithm is. The example of binary search is then used to show how it is an
O(log(n)) solution. Don’t forget to go through the practice problems in each chapter. These will definitely help to cement these ideas more firmly into your head.
Sorting and Selection
From there the book goes quickly into arrays and linked lists. Don’t be surprised if you find out that you are using these data structures already, and note that most programming languages already have built-in functions or methods for these data types, but it is nice to have a general understanding of how this works, as well as what the implications are on sorting an array and why they are fast to read, but if you have a list that needs to be updated, a linked list is most of the time preferable.
Recursion.. Recursion.. Recursion..
From there the book covers a topic I love. Recursion and then also ties it nicely into the callstack of an algorithm and how boxing and unboxing works. These topics are somewhat difficult to understand, and this is a great way to gain exposure to a topic that I’ve seen even fairly advanced developers struggle with.
I did not realize how long a full-on book review could be. Just kidding. I am not going to cover the whole book here, but you ought to check it out if this is a topic you need to understand. You can buy it from many places, but I found it on Amazon for about $39.95 new, but I found a great condition used copy for half that. Hope you found this useful, and let me know what you think. Also here is Aditya’s github repository with many of the problems for each chapter worked out. There are examples in the book given in Python, but this repository covers a few other languages too.