Skip to content

15 of 56 topics ready

Data Structures and Algorithms

A hands-on handbook that takes you from counting steps and linked lists to balanced trees, graphs, dynamic programming and the limits of computation. Every topic is explained in plain prose, traced step by step, built from scratch in Python and checked against the libraries used in practice.

9parts
15topics ready
56topics planned
103runnable examples

Nine parts, one path

Start with the core, then branch out by interest.

FoundationsHow to state what an algorithm must do, prove that it does it and count what it costs: abstract data types, proofs and invariants, the mathematical toolkit, asymptotic notation, recursion, recurrences, amortized analysis and the probability that randomized methods rely on.2 of 8 topics readyLinear structuresSequences stored one after another: contiguous arrays and the dynamic arrays behind Python lists, linked lists in all their variants, stacks and queues.2 of 4 topics readySearching and sortingFinding an item and putting items in order, the two problems that teach most of algorithm analysis: binary search and its traps, the elementary sorts, merge sort and quicksort, the comparison lower bound, sorting in linear time, selection, and how real libraries sort.2 of 7 topics readyTreesHierarchies and the search trees built on them: traversals and expression trees, threaded trees, binary search trees, the balanced families (AVL, red-black, splay, B-trees), heaps, augmented trees and the range-query trees used in competitive and production code.4 of 11 topics readyHashingFinding items in constant expected time: hash functions, collision resolution by chaining and open addressing, how production hash tables are engineered and attacked, and the probabilistic structures that trade exactness for space.1 of 3 topics readyGraphsNetworks of things and the classic algorithms on them: representations, breadth-first and depth-first search, topological order, connectivity, union-find, minimum spanning trees, shortest paths and maximum flow.2 of 9 topics readyAlgorithm designThe general strategies behind most algorithms: divide and conquer, greedy choice with its exchange arguments, dynamic programming, backtracking with branch and bound, number theory and randomization.1 of 8 topics readyStringsSearching text and indexing it: naive matching, Rabin-Karp, Knuth-Morris-Pratt, Boyer-Moore, tries and suffix arrays, each traced character by character and compared with what Python's own string search does.1 of 4 topics readyComplexityWhat efficient algorithms cannot do: decision problems, polynomial-time reductions and NP-completeness, then approximation algorithms that come with a guarantee when exact answers are out of reach.0 of 2 topics ready

Inside every topic

Every topic has the same shape, so once you know one you can find your way around all of them.

Readable theoryPlain prose, with formulas and diagrams drawn as images.
From-scratch codeA package of small modules, one idea per file, fully commented.
Runnable examplesShort scripts, each showing one idea or one library comparison.
A sample projectAn end-to-end command line project on a realistic task.
A guided notebookA tour that imports the package and shows results inline.
TestsChecks for every worked example and every property the page claims.

Learning path

Start with the core and branch out by interest. Each part lists what it builds on.

How the parts of the handbook build on each other

Getting started

You need Python 3.11 or newer. The repository installs as one package, so every example and project script can import the topic it belongs to. The data structures themselves use only the standard library; plotting, notebooks and the library comparisons need the dependency groups in pyproject.toml, and each topic names the groups it needs near the top of its README.

With uv:

uv sync --group dev --group graphs
uv run python trees/heaps-and-priority-queues/examples/worked_example.py
uv run pytest

With pip 25.1 or newer:

python -m venv .venv
source .venv/bin/activate
pip install -e . --group dev --group graphs
python trees/heaps-and-priority-queues/examples/worked_example.py
pytest