A textbook

Modern Algorithm Design

Design algorithms from primitives, and know what to demand of them.

Modern Algorithm Design teaches you to design algorithms and data structures, not to memorize them. Its claim is that much of algorithm design can be understood through a small set of recurring ideas, called primitives, and the ways they compose. Machines can now search design spaces at a scale no person can, so the book trains the skill that stays with you: knowing what to ask for, what must hold, and how an answer can fail.

Read the book Code on GitHub

Cover of Modern Algorithm Design by Mario Brcic: a glass bottle holding a swirl of blue and gold light, on a cream background.

What it is

A textbook, online at modernalgorithmdesign.com. Six chapters are published so far, from Contracts and cost models to Paths and trees, and a new chapter appears each week during the lecture weeks. Every primitive comes with its label: what it assumes, what it costs, and how it fails.

Who it is for

Anyone who wants to design with algorithms, whether they build the design themselves, ask an AI to build it, or work with an AI to frame the problem. The chapters hand you a problem before they hand you its solution. Some boxes ask you to put the AI away and work the problem out alone, because an ability you have never had to use may not be yours.

What makes it different

A primitive is taught by what it buys and where it breaks, so you can compose it with others and still predict the result. The book treats vocabulary as central, because in the age of AI a precise word is also a precise specification.

Code you can check

Each structure is written three times: in Python, the version the book prints; in Rust, the fast one; and in Lean. Each promise a structure makes is labelled: Lean states and proves the promises it can, and the others are tested or measured, each with its label. In the companion library, differential conformance tests run the three versions on shared inputs, Lean against Rust and then Rust against Python, and the book's code listings are checked against the library. A mismatch fails the build. The public repository at github.com/mbrcic/algodesign is an export of the code and does not include that test harness.

More

Use it in a course, or tell me what breaks.

Corrections and questions from readers are how the book gets better.

Get in touch