The algorithms course you play.
A full data-structures-and-algorithms curriculum rebuilt as playable games — 99 lessons on 26 ordered ladders. You drive each problem and lose to your own instincts, then meet the algorithm that never does. The pseudocode, complexity, a worked trace and a quiz come after, once it's already clicked. 29 rungs are marked Core: the spine to play first if you are preparing for an interview.
The moves
The handful of techniques that turn an O(n²) loop into an O(n) one, the four containers everything else is built from, and the sorts underneath half of all algorithms.
Throw away half the answers
The first idea in the subject: if the space is ordered, you never have to look at most of it.
Two pointers and a window
Four ways to make one pass do the work of two nested loops — then the stack that remembers which earlier element still matters.
- The Closing GapTwo PointersCore Start here Don't memorize the two-pointer trick — watch the gap close.
- The Dutch National FlagThree-Way PartitionCoreDon't memorize sort-colors — watch three pointers sort it.
- The Moving FrameSliding WindowCoreDon't memorize the sliding window — watch it glide.
- The Running TotalPrefix SumsCoreDon't memorize prefix sums — watch the running total build.
- The Waiting LineMonotonic StackCoreDon't memorize the monotonic stack — watch it resolve.
One pass, constant space
Three algorithms that see each element exactly once and keep almost nothing — including one that samples a stream whose length it does not know.
The four containers
Sequence, discipline, lookup, priority. Every structure further down this page is one of these four with a better answer to one question.
- The Chain of NodesLinked List Start here Don't memorize the linked list — watch the pointers move.
- LIFO & FIFOStack & QueueCoreDon't memorize stacks and queues — watch them fill and drain side by side.
- The Instant LookupHash TableCoreDon't memorize the hash table — watch it drop keys into buckets.
- Sift Up, Sift DownHeap & Priority QueueCoreDon't memorize the heap — watch values sift up and down.
The comparison sorts
Divide, partition, heapify — three routes to n log n, then the hybrid your language actually ships.
Beating n log n
Stop comparing and start counting. Three linear sorts that need to know something about the keys — and the one for data that does not fit in memory.
- No ComparisonsCounting & Radix Sort Start here Don't memorize counting sort — watch it sort without a single comparison.
- Scatter, Sort, GatherBucket SortDon't memorize bucket sort — watch values fall into place.
- Radix SortSorting Without ComparingDon't memorize radix sort — play it.
- External Merge SortBigger Than MemoryDon't memorize external merge sort — play it.
Nearly sorting
Two problems that look like sorting and are cheaper than it: find the k-th element without ordering the rest, and fix a permutation in place.
Structures worth building
What you reach for when an array stops being enough — balanced trees, range queries, the on-disk shapes a database actually uses, and the sketches that trade exactness for memory.
Keeping a tree balanced
The unbalanced version first, so the next four read as answers to the same failure — rotate on insert, colour the nodes, randomise the priorities, or move what was just used to the top.
- The Ordered TreeBinary Search TreeCore Start here Don't memorize the BST — watch it grow.
- The Tree That Rebalances ItselfAVL TreeDon't memorize AVL rotations — watch the tree rebalance itself.
- Red-Black TreeBalance in Two ColorsDon't memorize the red-black tree — play it.
- TreapBalance by ChanceDon't memorize the treap — play it.
- Splay TreeTouch It, Lift ItDon't memorize the splay tree — play it.
Walking a tree cleverly
Traverse it without a stack, then answer "what is the lowest common ancestor?" in logarithmic time.
Answering a range in log time
Blocks first, because it is the only one whose idea fits in a sentence — every structure above it is an answer to "what if the blocks were a tree?".
- Sqrt DecompositionBlocks of Root-N Start here Don't memorize sqrt decomposition — play it.
- Bits Do the WalkingFenwick TreeDon't memorize the binary indexed tree — watch the bits do the walking.
- The Segment TreeDon't memorize the segment tree — watch it answer ranges in log time.
- Lazy Segment TreeUpdate LazilyDon't memorize lazy propagation — play it.
- Persistent Segment TreeEvery Version KeptDon't memorize the persistent segment tree — play it.
- Interval TreeWhat Contains This?Don't memorize the interval tree — play it.
- Mo's AlgorithmReorder to WinDon't memorize Mo's algorithm — play it.
Structures a database ships
What changes when the structure lives on a disk, is written by a thousand machines at once, or has to survive an editor undoing your last keystroke.
- How Databases Stay BalancedB-TreesCore Start here Don't memorize B-trees — watch a node overflow and split.
- LSM-TreeWrite Fast, Merge LaterDon't memorize the LSM-tree — play it.
- Express LanesThe Skip ListCoreDon't memorize the skip list — ride its express lanes.
- Piece Table & RopeEdit Without CopyingDon't memorize the piece table — play it.
- Consistent HashingThe RingDon't memorize consistent hashing — play the ring.
Trading exactness for memory
Four structures that answer a question wrongly on purpose, with a bound on how wrong — and are the only practical answer at a billion items.
- Bloom FilterMaybe Yes, Never No Start here Don't memorize the Bloom filter — play it.
- Count–Min SketchCounting in Tiny SpaceDon't memorize the Count–Min Sketch — play it.
- Counting a Crowd in KilobytesHyperLogLogCoreDon't memorize HyperLogLog — watch leading zeros count a crowd.
- MinHashSimilarity in a SignatureDon't memorize MinHash — play it.
Graphs
The universal model. Walk it, find the cheapest way across it, work out what it is connected to, then push as much through it as it will take.
Walking a graph
Breadth then depth — the two orders everything else in this arc is built on — then two walks with a twist.
- BFSThe FloodCore Start here Don't memorize breadth-first search — play it.
- Build OrderDFS & Topological SortCoreDon't memorize topological sort — play it.
- Bidirectional BFSMeet in the MiddleDon't memorize bidirectional BFS — play it.
- Eulerian PathEvery Edge, OnceDon't memorize Hierholzer's algorithm — play it.
The cheapest way across
Dijkstra first, then the three algorithms that exist because of something Dijkstra cannot do: use a hint, survive a negative edge, or answer every pair at once.
- DijkstraThe Last MileCore Start here Don't watch Dijkstra's algorithm — play it.
- A* SearchThe AscentDon't memorize A* — fly it.
- The Patient RouterBellman-FordDon't memorize Bellman-Ford — watch the distances settle.
- Every Vertex a Stepping StoneFloyd–WarshallDon't memorize Floyd–Warshall — watch the distance matrix improve.
What is connected to what
The structure that answers it in almost constant time, the two spanning trees built on top of it, and then the parts of a graph whose removal breaks it.
- Six DegreesUnion-Find Start here Don't memorize the Disjoint Set Union — play it.
- The Cheapest GridKruskal's MSTDon't memorize Kruskal's algorithm — watch it wire up a network.
- Grow the Cheapest TreePrim’s MSTDon't memorize Prim's algorithm — watch the tree grow.
- Cycles Into ComponentsTarjan’s SCCCoreDon't memorize Tarjan's algorithm — watch cycles collapse into components.
- Bridges & Articulation PointsThe Weak LinksDon't memorize Tarjan's bridge-finding — play it.
Pushing as much as it will take
Max flow, then the same problem with a price on each edge, then the assignment problem that turns out to be the same thing again.
Searching a space
Three answers to the same question — never solve a subproblem twice, take the locally best choice when that is provably enough, or try everything and undo.
DP along one axis
The four that teach the whole idea: a running best, a count, a capacity, and a length. Play them in this order and the recurrence stops being a trick.
- The Best StreakKadane's AlgorithmCore Start here Don't memorize Kadane's algorithm — watch the best streak emerge.
- The Fewest CoinsCoin ChangeCoreDon't memorize coin change — watch the table fill.
- The Loaded Bag0/1 KnapsackCoreDon't memorize the knapsack DP — watch the table fill.
- The Longest ClimbLongest Increasing SubsequenceDon't memorize the LIS — watch it build.
DP across two sequences
The same grid twice — once counting what matches, once counting what it costs to fix what does not.
When the state is not a number
What to do when the thing you index by is a subtree, a subset, or a digit position — and when to give up on DP and split the search in half.
When greedy is provably enough
Two problems where the locally best choice is optimal, and then the lesson that tells you how to know which is which.
- Finish First, Fit the MostInterval Scheduling Start here Don't memorize activity selection — watch the greedy choice pay off.
- Frequent Symbols, Short CodesHuffman CodingDon't memorize Huffman coding — watch the tree assemble itself.
- Greedy vs Dynamic ProgrammingWhen Is Greedy Safe?Don't guess which technique a problem needs — play both.
Try, fail, undo
Enumerate everything, then add a constraint, then add a hard one — the same recursion each time, pruned harder.
- Push, Recurse, PopSubsets by Backtracking Start here Don't memorize backtracking — watch the decision tree grow and unwind.
- Cut the Dead BranchesCombination SumDon't memorize combination sum — watch the dead branches get cut.
- The StandoffN-QueensCoreDon't memorize backtracking — watch it try, clash, and undo.
- Guess, Hit a Wall, EraseSudoku SolverDon't memorize the Sudoku solver — watch it guess, hit a wall and erase.
Text
Match a pattern without re-reading a character, then index the text so you never scan it again.
Matching without backing up
Hash it, then the three algorithms that never re-read a character — and finally the one that matches a thousand patterns in the same pass.
- The Rolling HashRabin-Karp Start here Don't memorize Rabin-Karp — watch the hash roll.
- The Non-BacktrackerKMPDon't memorize KMP — watch the pattern slide.
- Slide the Z-BoxZ-AlgorithmDon't memorize the Z-algorithm — watch the Z-box slide.
- Let the Mirror Do the WorkManacher’s AlgorithmDon't memorize Manacher's algorithm — watch the mirror do the work.
- One Pass, Every WordAho-CorasickDon't memorize Aho-Corasick — watch one pass catch every pattern.
Indexing the text instead
Pay once to build the index, then stop scanning the text at all.
Numbers and geometry
The classics that keep turning up in cryptography, in compilers and in the one interview question nobody prepares for.
Number theory, in order
GCD, then what it also gives you, then the exponentiation every crypto library runs — then finding primes, testing them, and finally factoring one.
- The Biggest Tile That FitsEuclidean GCD Start here Don't memorize the Euclidean algorithm — see it as tiling.
- Extended Euclidean & CRTgcd, and a BonusDon't memorize the extended Euclidean algorithm — play it.
- Climb in Doubling JumpsModular ExponentiationDon't memorize fast power — watch the exponent climb in doubling jumps.
- Sieve of EratosthenesPrime TimeFind every prime under 100 without dividing once.
- Miller–RabinProbably PrimeDon't memorize Miller–Rabin — play it.
- Pollard's RhoFactor by CollisionDon't memorize Pollard's rho — play it.
Multiplying faster than school
Three divide-and-conquer results that beat the obvious quadratic — on integers, on signals, and on a recurrence you thought needed a loop.
Points, lines and giving up
Two sweeps over geometry, and then the algorithm for when the space is too ugly for any of the above.
How to use this hub
Play the lesson
Drive the algorithm yourself and lose — then watch it win. Intuition before formalism.
Read the theory
Pseudocode, complexity, a worked trace and a quiz — now that it has clicked.
Practice it
Solve the matching coding challenge in your browser, tests and all.
Keep it
Review the flashcards and the Big-O cheatsheet so it sticks for the interview.
The patterns underneath
Individual algorithms are worth learning, but the real prize is the handful of patterns they share — the moves that unlock unfamiliar problems in an interview.
Divide & Conquer
Split in half, solve, combine — binary search, merge sort, quicksort.
Two Pointers & Windows
Move indices instead of re-scanning — the sliding window.
BFS / DFS
Explore in rings or dive deep — every graph and tree traversal.
Dynamic Programming
Cache overlapping subproblems — edit distance, shortest paths.
Greedy
Take the locally best choice — Kruskal’s MST, Dijkstra.
Backtracking
Try, recurse, undo — N-Queens and constraint search.
Complexity reference
The Big-O you'll be asked to recite — data-structure operations and the sorting algorithms compared. The full version lives on the Big-O cheatsheet.
Data structure operations · average case
| Structure | Access | Search | Insert | Delete |
|---|---|---|---|---|
| Array | O(1) | O(n) | O(n) | O(n) |
| Dynamic Array | O(1) | O(n) | O(1)* | O(n) |
| Hash Table | — | O(1) | O(1) | O(1) |
| Linked List | O(n) | O(n) | O(1) | O(1) |
| Stack / Queue | O(n) | O(n) | O(1) | O(1) |
| Binary Search Tree | O(log n) | O(log n) | O(log n) | O(log n) |
| Heap | O(1)† | O(n) | O(log n) | O(log n) |
* amortized · † peek the max/min
Sorting algorithms
| Algorithm | Best | Average | Worst | Space | Stable |
|---|---|---|---|---|---|
| Quicksort | O(n log n) | O(n log n) | O(n²) | O(log n) | No |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) | Yes |
| Heap Sort | O(n log n) | O(n log n) | O(n log n) | O(1) | No |
| Counting Sort | O(n + k) | O(n + k) | O(n + k) | O(k) | Yes |
Learn it. Practice it. Keep it.
Data structures & algorithms — frequently asked questions
What is the best way to learn algorithms and data structures?
Build intuition before memorizing. Watching an animation or grinding LeetCode templates rarely sticks because it's passive — you remember what you've done, not what you've watched. Each lesson here is a playable game: you solve the problem yourself and fail, then see exactly why the algorithm wins, followed by the formal pseudocode, time and space complexity, a worked trace and a quiz. Feeling the problem first, then formalizing it, is what makes data structures and algorithms stick for interviews and real work.
Do these algorithm lessons help with coding interviews?
Yes. Data structures and algorithms (DSA) are half of every technical interview loop — system design is the other half, covered separately on the site. The lessons target the graph, shortest-path, sorting, search and dynamic-programming topics that come up most often, and they build the reasoning behind each algorithm so you can adapt under pressure instead of recalling a memorized template.
Which algorithm should I learn first?
Start with Dijkstra's shortest-path algorithm (The Last Mile). Graphs and shortest paths underpin pathfinding, network routing and a large share of interview questions, and the priority-queue idea at Dijkstra's core carries straight over to BFS, A*, and Prim's algorithm. From there, branch into sorting, binary search and dynamic programming as they're added.
Do I need to be good at math to learn algorithms?
No. These lessons lead with visual intuition and a concrete story, not proofs. You'll meet Big-O notation and see why each algorithm is correct, but the understanding comes from playing the problem — driving it, predicting its moves, and breaking it — not from heavy mathematics.
How is this different from a textbook, a video, or LeetCode?
You participate instead of watching. A textbook explains and a video shows; here you drive the algorithm, predict its next step, and even sabotage it to see where it breaks. That active recall, paired with the full theory (pseudocode, complexity, a worked trace and a quiz), builds far more durable understanding than passively reading or grinding problems before the concept has clicked.
Are the algorithm lessons free?
Yes — every lesson is completely free, runs entirely in your browser with no account or sign-up, and is keyboard-playable with a text version of each diagram for screen readers.