# TAOCP 2.2.3 Linked Allocation

> Study guide to TAOCP 2.2.3 Linked Allocation. Linked lists, the available-space (free) list, and how to implement stacks and queues with links. The…

Updated October 20, 2026.

## Summary {#summary}

TAOCP 2.2.3 Linked Allocation: Linked lists, the available-space (free) list, and how to implement stacks and queues with links. Budget about 9 hours; do exercises 1, 7 and 2.

The highlight is topological sorting: putting items in an order consistent with a set of "must come before" relations.

## Key facts {#key-facts}

- Week 51 of 145 on the cracked.guide path, in [TAOCP Vol 1: Fundamental Algorithms](https://cracked.guide/taocp/volume-1).
- Time budget: about 9 hours.
- 30 exercises in the section, rated 10 to M48; the guide picks 8.
- Picked exercises with Knuth's triangle for recommended: 1, 11, 17, 20, 29 and 23.
- Before you start: 2.2.2 Sequential Allocation and c pointers (clox).
- Terms it teaches: [Topological sort](https://cracked.guide/glossary/topological-sort).

## Week 51 goals {#objectives}

By the end of week 51 you can:

- Implement linked stacks and queues with an available-space list.
- Trace Knuth's topological sort using predecessor counts and successor lists.
- Recognize when input relations contain a cycle and no order exists.

## This week's steps {#steps}

- Read §2.2.3 Linked Allocation: This is a long and very rewarding section.
- Work the exercises (8 picked): Start with Ex 1, Ex 7, Ex 2; 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 section has 30 exercises, rated 10 to M48, and Knuth marks six of them with the triangle for recommended. Big, practical set. Topological sort exercises (11, 17 to 24) are the highlight. 13 and 25 are rated in the high 40s; leave them.

Worth your time:

- 1 (rated 10, recommended): Why the linked push never mentions overflow in the text's notation.
- 7 (rated 23): Reverse a singly linked list in place. The classic.
- 2 (rated 22): Write a general MIX insertion subroutine with the book's calling conventions.
- 11 (rated 24, recommended): List every valid topological order for a small example.
- 17 (rated 21, recommended): Run the topological sort by hand on the text's input.
- 20 (rated 24, recommended): Swap the queue inside topological sort for a stack and compare the results.
- 29 (rated 21, recommended): Return a whole list to the free list as fast as possible.
- 23 (rated 27, recommended): Make topological sort print an actual cycle when it gets stuck. The stretch, and a feature every build tool needs.

## Why it matters {#why}

Topological sort runs your build system, package manager and task scheduler. Free lists are the simplest memory allocator and still used in game engines and kernels.

## Before you start {#before}

- 2.2.2 Sequential Allocation
- C pointers (clox)

## How to approach it {#approach}

This is a long and very rewarding section. Implement the free-list allocator in C. Then implement Knuth's topological sort algorithm from the text, run it on a small dependency graph from a real project, and check the output order.

## Common traps {#traps}

- Losing nodes when you forget to return them to the free list.
- Topological sort with a cycle in the input: decide what your code should do.

## Links {#links}

- [Knuth's TAOCP page (editions, errata, MIX/MMIX)](https://www-cs-faculty.stanford.edu/~knuth/taocp.html)
- [Vol 1 errata (plain text, from Knuth)](https://www-cs-faculty.stanford.edu/~knuth/err1.textxt)
- [Wikipedia: Linked list](https://en.wikipedia.org/wiki/Linked_list)
- [Wikipedia: Topological sorting](https://en.wikipedia.org/wiki/Topological_sorting)
- [Wikipedia: Free list](https://en.wikipedia.org/wiki/Free_list)

---

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