# TAOCP 7.1.4 Binary Decision Diagrams (part 2)

> Study guide to TAOCP 7.1.4 Binary Decision Diagrams (part 2). Part 2 covers the rest of 7.1.4 (book pages 233 to 258): most functions have large BDDs, why…

Updated October 20, 2026.

## Summary {#summary}

TAOCP 7.1.4 Binary Decision Diagrams (part 2) covers the rest of 7.1.4 (book pages 233 to 258): most functions have large BDDs, why variable ordering can change sizes exponentially, finding a good order, local swaps and dynamic reordering by sifting (Algorithm J), and more. Budget about 8 hours; do exercises 147, 187 and 198.

Part 2 covers the rest of 7.1.4 (book pages 233 to 258): most functions have large BDDs, why variable ordering can change sizes exponentially, finding a good order, local swaps and dynamic reordering by sifting (Algorithm J), read-once functions, the bad news for multiplication, and zero-suppressed BDDs (ZDDs) with their family algebra, used for exact cover, tilings, word lists, paths in graphs and prime implicants. It ends with a short history and a caveat about when BDDs are the wrong tool.

## Key facts {#key-facts}

- Week 126 of 145 on the cracked.guide path, in [TAOCP Vol 4A: Combinatorial Algorithms, Part 1](https://cracked.guide/taocp/volume-4a).
- Time budget: about 8 hours.
- 267 exercises in the section, rated 05 to M47; the guide picks 8.
- Picked exercises with Knuth's triangle for recommended: 147, 187, 198, 208, 212, 225, 265 and 164.
- Before you start: 7.1.4 part 1.
- Terms it teaches: [BDD](https://cracked.guide/glossary/bdd), [ZDD](https://cracked.guide/glossary/zdd).

## Week 126 goals {#objectives}

By the end of week 126 you can:

- Compare BDD sizes for one function under two variable orders.
- Explain how sifting improves an order with adjacent variable swaps.
- Recognize when to use a ZDD instead of a BDD for families of sets.

## This week's steps {#steps}

- Read §7.1.4 Binary Decision Diagrams (part 2): Add AND/OR synthesis with a memo cache to your BDD.
- Work the exercises (8 picked): Start with Ex 147, Ex 187, Ex 198; log what you solve below.
- Write down one thing you'd explain to someone: A few sentences in your own words in Your notes: the idea, why it works, an example. 30 words ticks this.

## Exercises {#exercises}

This week covers exercises 108 to 267 of the 7.1.4 set (267 in all, rated 05 to M47, 91 recommended); this half has 160 exercises rated 10 to M47, with 55 recommended. Rough map: large BDDs and profiles 108 to 135, variable ordering and reordering 136 to 162, read-once functions and multiplication 163 to 185, ZDD basics 186 to 211, ZDD applications (exact cover, words, paths, cliques, prime implicants) 212 to 267.

Worth your time:

- 147 (rated 27, recommended): Work out the details of swapping two adjacent variables in place. The building block of every dynamic reordering heuristic.
- 187 (rated 20, recommended): Draw the ZDDs for all 16 functions of two variables and compare with your BDDs.
- 198 (rated 23, recommended): Write AND for ZDDs. Shows exactly where the different reduction rule changes the algorithm.
- 208 (rated 16, recommended): Count solutions from a ZDD by modifying the BDD counting algorithm.
- 212 (rated 25, recommended): Build a ZDD for an exact cover problem. Connects to the dancing links material in Vol 4B.
- 225 (rated 30, recommended): Build a ZDD of all simple paths between two vertices. This is the idea behind the Simpath algorithm used to count paths on grids.
- 265 (rated 21, recommended): Find the m-th smallest solution from a BDD. Ranking and unranking, which 7.2.1 uses throughout.
- 164 (rated M27, recommended): Find the largest BDD a read-once function can have. The stretch.

## Why it matters {#why}

Variable ordering can make a BDD tiny or exponential, a great lesson in representation choice. ZDDs are excellent for combinatorial families and come back in Vol 4B.

## Before you start {#before}

- 7.1.4 part 1

## How to approach it {#approach}

Add AND/OR synthesis with a memo cache to your BDD. Try two variable orders on the same function and watch the size change.

## Common traps {#traps}

- Assuming a good variable order is easy to find. Finding the best order is expensive in general; heuristics like sifting are what you use in practice.
- Mixing up BDD and ZDD reduction rules. ZDDs remove nodes whose HI branch goes to false, not nodes with equal branches.

## Links {#links}

- [Knuth's TAOCP page (editions, errata, MIX/MMIX)](https://www-cs-faculty.stanford.edu/~knuth/taocp.html)
- [Vol 4A errata (plain text, from Knuth)](https://www-cs-faculty.stanford.edu/~knuth/err4a.textxt)
- [Wikipedia: Zero-suppressed decision diagram](https://en.wikipedia.org/wiki/Zero-suppressed_decision_diagram)
- [Hacker News: ZDDs: A data structure for families of sets](https://news.ycombinator.com/item?id=2477011)

---

Source: https://cracked.guide/guide/knuth-w108-0
cracked.guide: A free, dated 145-week path to getting genuinely cracked at programming.
