Mastering Algorithms

An Extensive Reference of Commonly Used Algorithms

Mastering Algorithms is a free, structured guide to the algorithms and data structures that actually come up — in coursework, in technical interviews, and in production code. It covers 36 topics across nine areas, each with a plain-language explanation, a complexity analysis, a worked example traced step by step, and Python you can run.

What distinguishes it is the verification. Every code listing on this site is executed before it is published. Sorting algorithms are tested against Python's own sorted() across thousands of randomised inputs; pattern-matching algorithms are checked against brute force; the neural network's backpropagation is validated against numerically estimated gradients. Every worked example is traced from the algorithm printed on the same page, so the numbers in the walkthrough are the numbers the code actually produces.

That sounds like a low bar. It is not one most algorithm tutorials clear — and when a trace is wrong or an implementation does not match its stated complexity, the reader who is trying hardest to follow along is the one who gets stuck. In August 2026 the entire site was re-audited line by line and 58 corrections were applied. You can read more about that process on the about page.

What's Covered

Searching

Linear and binary search with the off-by-one traps spelled out, plus hash tables — the structure most real lookup code actually uses.

Graphs

Traversal, shortest paths and connectivity: DFS and BFS through to Dijkstra's, Bellman-Ford, Floyd-Warshall, A*, topological sort and strongly connected components.

Strings

KMP with its failure function derived, Rabin-Karp rolling hashes, Boyer-Moore, the Z-algorithm, and Manacher's for palindromes in linear time.

What Each Chapter Gives You

Where To Start

The chapters are ordered so each builds on the last, but nothing stops you jumping straight to what you need.

Browse All 36 Chapters →

Free to read in full. No account, no paywall, no signup.