The Algorithm Codex
by Alejandro Piad Morffis
$25
Most algorithm books fall into one of two traps: they are either dense academic tomes filled with dry proofs, or shallow "cookbooks" that offer recipes without understanding. The Algorithm Codex is designed to be the middle path.
This is a living book of the algorithms every programmer eventually meets, written for students, researchers, and developers who want to understand the why before the how. Every chapter closes with the same three questions: is it correct? how efficient? is it optimal?
The Philosophy: Code as Prose
This project is built on the principle of literate programming. The source code you see in the book isn't a snippet — it is the actual source used to build the Python package. There is no pseudo-code here, ever. Only runnable Python 3.13 that leverages modern features like PEP 695 generics and strict type protocols to ensure clarity and correctness. If a code block in the book is wrong, the book won't render.
Current Status: Five of Eight Parts are Live
Five of the eight planned parts now ship, for a total of 38 chapters of runnable, type-checked Python:
Part I — Searching and Sorting (chapters 1–7): linear and binary search, the geometry of inversions, merge / quick / heap sort, selection, and the linear-time loophole that breaks the Ω(n log n) lower bound.
Part II — Fundamental Data Structures (chapters 8–14): dynamic arrays, linked lists, stacks, queues, hash tables, Bloom filters, and the inverse-Ackermann magic of Union-Find.
Part III — Trees (chapters 15–22): binary trees, BSTs, AVL, treaps, heaps, tries, segment trees, and Fenwick trees.
Part IV — String Algorithms (chapters 23–30): brute force through KMP, Boyer-Moore, Rabin-Karp, Aho-Corasick, suffix arrays, and edit distance.
Part V — Graphs (chapters 31–38): representations, breadth-first and depth-first search, Dijkstra, relaxation under negative weights, minimum spanning trees, topological order and strong components, and max-flow min-cut.
Foundations + Primers: Big-O scaling intuition, the RAM model, and short appendices on modern Python syntax and the formal math behind asymptotic growth.
NOTE: This is still a work in progress. Parts I–V are stable; the remaining three parts are coming. By buying the PDF now you receive every future update via email notification at no additional cost.
The Grand Plan: 8 Volumes of Computation
Searching and Sorting ✓
Fundamental Data Structures ✓
Trees ✓
String Algorithms ✓
Graphs ✓
Dynamic Programming & Greedy Algorithms (In Progress)
Specialized Domains (Geometry, Number Theory, Game Theory)
Advanced Complexity (NP-Completeness and Approximation)
Why is this $25?
I believe foundational knowledge should be accessible to everyone, and most of my books are free to read online at books.apiad.net. The Codex is the exception, for now: getting 38 chapters of executable Python into the web reader is still on my list. Until then, this listing is the only place to get it.
What your purchase buys:
A high-quality PDF for offline study, and every future update at no additional cost.
The time to write the remaining three parts — dynamic programming and greedy algorithms, specialized domains, and advanced complexity.
Independent, open-source education that isn't behind a publisher.
If the price is a real obstacle, write to me at apiad@apiad.net. No one who wants to read this book should be unable to.