Algorithms explained
Step-by-step recipes that make a big problem small: throw away what cannot hold the answer, and always extend the cheapest option first.
Every algorithms concept
Binary search
Halve the problem until the answer has nowhere left to hide.
OPEN LESSON
Dijkstra’s shortest path
Grow the cheapest frontier until you reach the goal.
OPEN LESSON
Greedy algorithms
Take the best-looking step every time, and learn when that is enough.
OPEN LESSON
Sudoku solving
Constraints, propagation and backtracking: how a program fills the grid.
OPEN LESSON
Selection sort
Pick out the smallest item left, put it next in line, repeat: simple, slow, few swaps.
OPEN LESSON
Counting sort and radix sort
Sort by counting values instead of comparing them, then one digit at a time.
OPEN LESSON
Divide and conquer
Split a problem, solve the halves, join the answers: why merge sort takes n log n.
OPEN LESSON
Backtracking
Try a choice, check the rules, undo it when stuck: four queens on a small board.
OPEN LESSON
Two pointers technique
Two markers sweep a list once, doing the job of a loop inside a loop.
OPEN LESSON
Sliding window technique
A frame moves along a list, updating its total instead of adding everything again.
OPEN LESSON
Topological sort
Lining up tasks so that everything a task depends on comes before it.
OPEN LESSON
Knapsack problem
Packing the most value into a bag that is too small, one table cell at a time.
OPEN LESSON
Longest common subsequence
Finding the letters two words share in order, with a table, and how diff uses it.
OPEN LESSON
Travelling salesman problem
The shortest round trip through every city, and why nobody can find it fast.
OPEN LESSON
Rabin–Karp algorithm
Finding a pattern in a text by sliding a rolling hash along it.
OPEN LESSON
Run-length encoding
Squeezing repeated values into a count and a value, and when that backfires.
OPEN LESSON
Fast Fourier transform
Finding the waves inside a signal in n log n steps by splitting it into even and odd halves.
OPEN LESSON
Reservoir sampling
A fair random sample from a stream whose length nobody knows, in one pass.
OPEN LESSON
Monte Carlo tree search
Choosing a move by playing random games and keeping score in a growing tree.
OPEN LESSON