liveBook · Manning

What you will learn in Grokking Algorithms, Second Edition

by Aditya Bhargava

Chapter by chapter

Chapter 1: Introduction to algorithms

The introduction defines an algorithm and explains why the book focuses on algorithms that speed up tasks or solve interesting problems.

1.1 What you’ll learn about performance · 1.2 What you’ll learn about solving problems · 1.3 Binary search · 1.4 A better way to search · 1.5 Running time · 1.6 Big O notation · 1.7 Algorithm running times grow at different rates · 1.8 Visualizing different big O run times · 1.9 Big O establishes a worst-case run time · 1.10 Some common big O run times · 1.11 The traveling salesperson · 1.12 Recap

What you learn in chapter 1 →

Chapter 2: Selection sort

The chapter introduction explains why sorted data matters and why learning selection sort is worthwhile even when sorting is built in.

2.1 How memory works · 2.2 Arrays and linked lists · 2.3 Linked lists · 2.4 Arrays · 2.5 Terminology · 2.6 Inserting into the middle of a list · 2.7 Deletions · 2.8 Which is used more, arrays or linked lists? · 2.9 Selection sort · 2.10 Example code listing · 2.11 Recap

What you learn in chapter 2 →

Chapter 3: Recursion

The chapter introduces recursion’s importance, recommends hands-on ways to learn it, and defines pseudocode.

3.1 Recursion · 3.2 Base case and recursive case · 3.3 The stack · 3.4 The call stack · 3.5 The call stack with recursion · 3.6 Recap

What you learn in chapter 3 →

Chapter 4: Quicksort

The introduction presents divide and conquer as a reusable recursive technique to consider when familiar algorithms do not solve a new problem.

4.1 Divide and conquer · 4.2 Quicksort · 4.3 Big O notation revisited · 4.4 Merge sort vs. quicksort · 4.5 Average case vs. worst case · 4.6 Recap

What you learn in chapter 4 →

Chapter 5: Hash tables

The grocery-store price lookup example compares search speeds and motivates the need for hash tables.

5.1 Hash functions · 5.2 Use cases · 5.3 Using hash tables for lookups · 5.4 Preventing duplicate entries · 5.5 Using hash tables as a cache · 5.6 Recap · 5.7 Collisions · 5.8 Performance · 5.9 Load factor · 5.10 A good hash function · 5.11 Recap

What you learn in chapter 5 →

Chapter 6: Breadth-first search

The chapter introduction presents breadth-first search as a way to find shortest distances and shows that “shortest” can mean different things in different applications.

6.1 Introduction to graphs · 6.2 What is a graph? · 6.3 Breadth-first search · 6.4 Finding the shortest path · 6.5 Queues · 6.6 Implementing the graph · 6.7 Implementing the algorithm · 6.8 Running time · 6.9 Recap

What you learn in chapter 6 →

Chapter 7: Trees

The introduction places trees within graphs and shows why specialized trees matter for compression and database storage.

7.1 Your first tree · 7.2 File Directories · 7.3 A space odyssey: Depth-first search · 7.4 A better definition of trees · 7.5 Binary trees · 7.6 Huffman coding · 7.7 Recap

What you learn in chapter 7 →

Chapter 8: Balanced trees

The chapter introduction motivates balanced trees as a way to improve tree performance when other data structures fall short.

8.1 A balancing act · 8.2 Improving insertion speed with trees · 8.3 Shorter trees are faster · 8.4 AVL trees: A type of balanced tree · 8.5 Rotations · 8.6 How does the AVL tree know when it’s time to rotate? · 8.7 Splay trees · 8.8 B-trees · 8.9 What is the advantage of B-trees? · 8.10 Recap

What you learn in chapter 8 →

Chapter 9: Dijkstra’s algorithm

This introduction contrasts finding the path with the fewest segments with finding the fastest path when graph edges have travel times.

9.1 Working with Dijkstra’s algorithm · 9.2 Terminology · 9.3 Trading for a piano · 9.4 Negative-weight edges · 9.5 Implementation · 9.6 Recap

What you learn in chapter 9 →

Chapter 10: Greedy algorithms

The chapter introduction previews greedy strategies, NP-hard problems, and approximation algorithms.

10.1 The classroom scheduling problem · 10.2 The knapsack problem · 10.3 The set-covering problem · 10.4 Approximation algorithms · 10.5 Code for setup · 10.6 Calculating the answer · 10.7 Sets · 10.8 Back to the code · 10.9 Recap

What you learn in chapter 10 →

Chapter 11: Dynamic programming

The introduction defines dynamic programming as solving a hard problem by first solving smaller subproblems.

11.1 The knapsack problem (revisited) · 11.2 The simple solution · 11.3 Dynamic programming · 11.4 Knapsack problem FAQ · 11.5 What happens if you add an item? · 11.6 What happens if you change the order of the rows? · 11.7 Can you fill in the grid column-wise instead of row-wise? · 11.8 What happens if you add a smaller item? · 11.9 Can you steal fractions of an item? · 11.10 Optimizing your travel itinerary · 11.11 Handling items that depend on each other · 11.12 Is it possible that the solution will require more than two sub-knapsacks? · 11.13 Is it possible that the best solution doesn’t fill the knapsack completely? · 11.14 Longest common substring · 11.15 Making the grid · 11.16 Filling in the grid · 11.17 The solution · 11.18 Longest common subsequence · 11.19 Longest common subsequence—solution · 11.20 Recap

What you learn in chapter 11 →

Chapter 12: k-nearest neighbors

This chapter introduction previews classification with k-nearest neighbors, feature extraction, regression, and the algorithm’s uses and limitations.

12.1 Classifying oranges vs. grapefruit · 12.2 Building a recommendations system · 12.3 Feature extraction · 12.4 Regression · 12.5 Picking good features · 12.6 Introduction to machine learning · 12.7 OCR · 12.8 Building a spam filter · 12.9 Predicting the stock market · 12.10 A high-level overview of training an ML model · 12.11 Recap

What you learn in chapter 12 →

Chapter 13: Where to go next

The chapter previews brief introductions to additional algorithms and suggests further reading based on the reader’s interests.

13.1 Linear regression · 13.2 Inverted indexes · 13.3 The Fourier transform · 13.4 Parallel algorithms · 13.5 map/reduce · 13.6 Bloom filters and HyperLogLog · 13.7 Bloom filters · 13.8 HyperLogLog · 13.9 HTTPS and the Diffie–Hellman key exchange · 13.10 Locality-sensitive hashing · 13.11 Min heaps and priority queues · 13.12 Linear programming · 13.13 Epilogue

What you learn in chapter 13 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.