TAOCP Vol 1: Fundamental Algorithms · Week 37
TAOCP 2.2.5 Doubly Linked Lists: reading guide
Lists with links in both directions, making deletion and insertion anywhere cheap. Knuth illustrates them with a detailed discrete-event simulation of an elevator system.
Time About 7 hours this week
Why it matters
Doubly linked lists underpin LRU caches and editor buffers, and the elevator simulation is a crash course in discrete-event simulation, a technique still used for modeling systems.
Before you start
- 2.2.4 Circular Lists
- 1.4.2 Coroutines
How to approach it
Implement a doubly linked list with a header node and test insert and delete at all positions. The elevator simulation is long: read it for structure, focus on how the event list works, and do not try to trace every MIX line.
Exercises
Work every exercise rated 10 to 20; most are about tracing the algorithm by hand or tweaking one step, which is exactly the skill you want. Pick one or two rated 20 to 25 that involve modifying the algorithm and implement your modification in a real language with tests. Skip HM exercises unless you enjoy calculus, and treat anything rated 40+ as a research problem, not homework.
Traps
- Updating only one of the two links on insert or delete. Write the four pointer updates down before coding them.