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.

19 conceptsBeginner to Advanced

Every algorithms concept

AlgorithmsBeginner

Binary search

Halve the problem until the answer has nowhere left to hide.
OPEN LESSON
AlgorithmsIntermediate

Dijkstra’s shortest path

Grow the cheapest frontier until you reach the goal.
OPEN LESSON
AlgorithmsBeginner

Greedy algorithms

Take the best-looking step every time, and learn when that is enough.
OPEN LESSON
AlgorithmsIntermediate

Sudoku solving

Constraints, propagation and backtracking: how a program fills the grid.
OPEN LESSON
AlgorithmsBeginner

Selection sort

Pick out the smallest item left, put it next in line, repeat: simple, slow, few swaps.
OPEN LESSON
AlgorithmsIntermediate

Counting sort and radix sort

Sort by counting values instead of comparing them, then one digit at a time.
OPEN LESSON
AlgorithmsIntermediate

Divide and conquer

Split a problem, solve the halves, join the answers: why merge sort takes n log n.
OPEN LESSON
AlgorithmsIntermediate

Backtracking

Try a choice, check the rules, undo it when stuck: four queens on a small board.
OPEN LESSON
AlgorithmsBeginner

Two pointers technique

Two markers sweep a list once, doing the job of a loop inside a loop.
OPEN LESSON
AlgorithmsBeginner

Sliding window technique

A frame moves along a list, updating its total instead of adding everything again.
OPEN LESSON
AlgorithmsIntermediate

Topological sort

Lining up tasks so that everything a task depends on comes before it.
OPEN LESSON
AlgorithmsIntermediate

Knapsack problem

Packing the most value into a bag that is too small, one table cell at a time.
OPEN LESSON
AlgorithmsIntermediate

Longest common subsequence

Finding the letters two words share in order, with a table, and how diff uses it.
OPEN LESSON
AlgorithmsIntermediate

Travelling salesman problem

The shortest round trip through every city, and why nobody can find it fast.
OPEN LESSON
AlgorithmsIntermediate

Rabin–Karp algorithm

Finding a pattern in a text by sliding a rolling hash along it.
OPEN LESSON
AlgorithmsBeginner

Run-length encoding

Squeezing repeated values into a count and a value, and when that backfires.
OPEN LESSON
AlgorithmsAdvanced

Fast Fourier transform

Finding the waves inside a signal in n log n steps by splitting it into even and odd halves.
OPEN LESSON
AlgorithmsIntermediate

Reservoir sampling

A fair random sample from a stream whose length nobody knows, in one pass.
OPEN LESSON
AlgorithmsAdvanced

Monte Carlo tree search

Choosing a move by playing random games and keeping score in a growing tree.
OPEN LESSON