15 Minutes
Cover of Grokking Algorithms

Technology and the Future · 15 min

Grokking Algorithms

Aditya Bhargava · 2016

Who it's for

For students, beginning programmers, and curious readers who want to understand how searches, routes, and recommendations work, without a lot of math. This is an accessible, illustrated introduction that keeps things light.

Read it in the app

⚡ Free to download • 🎁 One full book free every day

🎧 Listen to this summary in the app

Every summary has audio narration. Open the app to read it or listen to it.

3 ideas to take with you

1

Breadth-first search explains why a friend request to a friend of a friend is an easy suggestion to make.

2

Assigning weights to connections changes the answer: the route with the fewest stops may not be the fastest.

3

For very difficult problems, a rule of thumb that delivers a good result quickly is often worth more than a perfect solution that takes too long.

“
Organizing your data once can save you thousands of searches later.
An idea from Grokking Algorithms, in the words of 15 Minutes

Preview

Start reading now

An Illustrated Guide That Takes the Fear Out of Math

Grokking Algorithms, by Aditya Bhargava, published in 2016, is an introduction to computer science written for people who find the subject intimidating. Instead of pages of formulas, it uses hand-drawn illustrations, everyday examples, and very little math. The original subtitle promises an illustrated guide for programmers and curious readers, and it delivers on that promise.

An algorithm is simply a recipe: a sequence of steps for solving a problem. The book introduces the classics, the problems each one solves, and the reasoning behind them. The Python code examples are short, and even if you don't program, you can follow the ideas through the illustrations.

The underlying idea is that knowing a few basic algorithms helps you choose the right tool. When you have two ways to solve a problem, knowing which is faster and why makes a difference in systems that serve thousands of people.

Binary Search: Guessing with a Method

The first algorithm is binary search. The illustration is a game of guessing a number between 1 and 100. If you guess 1, then 2, then 3, it could take a hundred tries. If you start in the middle and each answer tells you whether the number is higher or lower, you eliminate half the possibilities with every guess and get the answer in just a few turns.

Binary search only works when the list is sorted, which is why dictionaries and phone books are organized alphabetically. Nobody reads every name to find one: you open to the middle and adjust from there. In a list with a million items, the method finds its target in about twenty steps.

The lesson is that organizing data before searching can pay off enormously. Often, the work of putting things in order once saves you thousands of searches later.

Big O: Measuring How the Cost Grows

The book introduces Big O notation, the language used to discuss algorithm speed. It doesn't measure seconds, but rather how the number of steps grows as the amount of data increases. It's a way to compare methods without depending on a particular computer.

Going through an entire list to find an item grows in direct proportion to the list's size, which is called linear time. Binary search grows very slowly, in what's called logarithmic time. Sorting in the simplest way grows much faster. And some problems have costs that explode, such as testing every possible route between many cities.

The takeaway is that with a little data, almost any method will do, but with a lot, the difference is enormous. A spreadsheet that runs smoothly with a hundred rows can freeze with a hundred thousand, and the reason lies in how the cost grows.

11 more sections and the quiz

Continue in the app

Read the whole summary, finish with the Grokking Algorithms quiz and follow the guided Journeys. No ads in the app.

About Aditya Bhargava

Aditya Bhargava is a software engineer and the author of Grokking Algorithms, published in 2016. He also created the book's illustrations, which helps explain its visual style. He maintains a blog featuring illustrated articles about programming, including his well-known visual guide to functors, applicatives, and monads.

Explore