Data structures and algorithms
A university course in data structures and algorithms that picks up where the Software intro lessons stop: cost analysis, heaps, hashing, tries, balanced trees, union-find, graph algorithms, greedy and divide and conquer, dynamic programming, backtracking, string matching and the patterns that solve interview problems. Every lesson is a structure you can step through, a short quiz and usually a small Python exercise.
Measuring cost
How to count the work an algorithm does, beyond a first look at Big O. Start with the Software lesson on Big O and the Maths lessons on logarithms and recurrences, which already cover counting steps and unrolling a recurrence.
-
Lesson 01 · 12 min
Comparing growth rates: O, Omega and Theta
8 stepsNot started -
Lesson 02 · 14 min
Amortised analysis: the accounting and potential methods
10 stepsNot started -
Lesson 03 · 12 min
Proving space cost: auxiliary space and recursion depth
8 stepsNot started -
Lesson 04 · 14 min
The master theorem
10 stepsNot started -
Lesson 05 · 14 min
Expected cost of randomised algorithms
11 stepsNot started
Linear structures in depth
Linked lists, stacks, queues and deques, built by hand and used to solve real problems. Builds on the Software lessons on arrays and lists and on stacks and queues.
-
Lesson 06 · 12 min
Linked lists: singly, doubly and circular
8 stepsNot started -
Lesson 07 · 12 min
Stacks at work: brackets, undo and expression evaluation
10 stepsNot started -
Lesson 08 · 12 min
Ring buffers and deques under the hood
10 stepsNot started -
Lesson 09 · 14 min
Monotonic stacks and queues
11 stepsNot started
Hashing and heaps
What happens inside a hash map when keys collide, and the heap that keeps the smallest item on top. Builds on the Software lesson on hash maps, which shows buckets, collisions and a table growing.
-
Lesson 10 · 14 min
Chaining vs probing: expected cost and clustering
9 stepsNot started -
Lesson 11 · 14 min
Load factor, resizing and universal hashing
8 stepsNot started -
Lesson 12 · 12 min
Binary heaps: sift up and sift down
8 stepsNot started -
Lesson 13 · 14 min
Priority queues and heapsort
8 stepsNot started
Search trees
Trees that keep data sorted, and how they stay balanced. Builds on the Software lesson on trees, which covers search, insert and a tree that turns into a line; the Databases lesson on B-trees covers wide nodes on disk.
-
Lesson 14 · 14 min
Tree traversals: pre-order, in-order, post-order and level order
9 stepsNot started -
Lesson 15 · 14 min
BST delete, successor and predecessor
10 stepsNot started -
Lesson 16 · 14 min
AVL trees and rotations
9 stepsNot started -
Lesson 17 · 15 min
2-3 trees and red-black trees
10 stepsNot started -
Lesson 18 · 14 min
Tries: trees of letters
10 stepsNot started
Graph algorithms
Storing graphs and walking them in order. Builds on the Software lessons on graphs and on BFS and DFS, and the Maths lesson on graph theory.
-
Lesson 19 · 14 min
Adjacency lists and adjacency matrices
9 stepsNot started -
Lesson 20 · 14 min
Multi-source and 0-1 BFS on grids
10 stepsNot started -
Lesson 21 · 14 min
DFS in depth: discovery times and cycle detection
10 stepsNot started -
Lesson 22 · 14 min
Topological sort
10 stepsNot started -
Lesson 23 · 14 min
Connected components and grid flood fill
8 stepsNot started -
Lesson 24 · 14 min
Union-find: merging groups fast
10 stepsNot started -
Lesson 25 · 15 min
Strongly connected components
11 stepsNot started
Greedy and divide and conquer
Two ways to design an algorithm, and how to prove they work. Builds on the Software lessons on sorting (insertion sort, merge sort, Timsort) and recursion and the Maths lesson on proofs.
-
Lesson 26 · 14 min
Greedy choices: the exchange argument and when greedy fails
10 stepsNot started -
Lesson 27 · 14 min
Interval scheduling
10 stepsNot started -
Lesson 28 · 14 min
Huffman coding
10 stepsNot started -
Lesson 29 · 14 min
Merge sort's recurrence and counting inversions
8 stepsNot started -
Lesson 30 · 15 min
Quicksort and quickselect: partitions and pivots
9 stepsNot started -
Lesson 31 · 14 min
Why comparison sorts can't beat n log n
10 stepsNot started -
Lesson 32 · 14 min
Counting sort and radix sort
11 stepsNot started
Shortest paths and spanning trees
Cheapest routes and cheapest networks over weighted graphs. Uses the heaps and union-find from earlier modules and the greedy proofs from the module before.
-
Lesson 33 · 14 min
Dijkstra's algorithm
11 stepsNot started -
Lesson 34 · 14 min
Bellman-Ford and negative edges
9 stepsNot started -
Lesson 35 · 14 min
Shortest paths in a DAG
10 stepsNot started -
Lesson 36 · 14 min
Minimum spanning trees with Kruskal
10 stepsNot started -
Lesson 37 · 14 min
All-pairs shortest paths with Floyd-Warshall
10 stepsNot started -
Lesson 38 · 14 min
Minimum spanning trees with Prim
11 stepsNot started
Dynamic programming and backtracking
The common shapes of dynamic programming, and searching every option without wasting work. Builds on the Software lesson on dynamic programming, which covers memoisation and tables.
-
Lesson 39 · 14 min
Defining states and transitions
9 stepsNot started -
Lesson 40 · 14 min
The knapsack problem
9 stepsNot started -
Lesson 41 · 15 min
Longest common subsequence and edit distance
11 stepsNot started -
Lesson 42 · 14 min
Longest increasing subsequence
10 stepsNot started -
Lesson 43 · 14 min
Grid paths and counting
10 stepsNot started -
Lesson 44 · 14 min
Backtracking: subsets and permutations
9 stepsNot started -
Lesson 45 · 14 min
N-queens and pruning
10 stepsNot started
Strings and problem-solving patterns
Fast text search and the patterns that crack most interview problems. Builds on the Software lessons on strings and on searching.
-
Lesson 46 · 12 min
Naive string search
9 stepsNot started -
Lesson 47 · 15 min
KMP: never look back
9 stepsNot started -
Lesson 48 · 14 min
Rabin-Karp and rolling hashes
9 stepsNot started -
Lesson 49 · 12 min
Two pointers
9 stepsNot started -
Lesson 50 · 15 min
Sliding window
9 stepsNot started -
Lesson 51 · 14 min
Binary search on the answer
10 stepsNot started -
Lesson 52 · 12 min
Prefix sums
8 stepsNot started
Special topics
Stand-alone deep dives. Take them any time after the module they build on.
-
Lesson S1 · 15 min
Segment trees and Fenwick trees
Builds on Search trees
10 stepsNot started -
Lesson S2 · 14 min
Bloom filters
Builds on Hashing and heaps
9 stepsNot started -
Lesson S3 · 14 min
A* search
Builds on Shortest paths and spanning trees
9 stepsNot started -
Lesson S4 · 14 min
Max flow and min cut
Builds on Shortest paths and spanning trees
10 stepsNot started -
Lesson S5 · 14 min
P, NP and hard problems
Builds on Dynamic programming and backtracking
10 stepsNot started