# TAOCP 6.2.2 Binary Tree Searching

> Study guide to TAOCP 6.2.2 Binary Tree Searching. Binary search trees: insertion, deletion, the average cost of random BSTs, and optimal BSTs built with…

Updated October 20, 2026.

## Summary {#summary}

TAOCP 6.2.2 Binary Tree Searching: Binary search trees: insertion, deletion, the average cost of random BSTs, and optimal BSTs built with dynamic programming when access frequencies are known. Budget about 8 hours; do exercises 1, 3 and 10.

## Key facts {#key-facts}

- Week 110 of 145 on the cracked.guide path, in [TAOCP Vol 3: Sorting and Searching](https://cracked.guide/taocp/volume-3).
- Time budget: about 8 hours.
- 49 exercises in the section, rated 15 to M47; the guide picks 8.
- Picked exercises with Knuth's triangle for recommended: 3, 10, 14, 16, 13, 23 and 45.
- Before you start: 2.3 Trees and 6.2.1 Searching an Ordered Table.

## Week 110 goals {#objectives}

By the end of week 110 you can:

- Implement BST insertion, search and deletion, including two-child deletion.
- Explain why inserting keys in sorted order makes a degenerate tree.
- Use dynamic programming to build an optimal BST from access frequencies.

## This week's steps {#steps}

- Read §6.2.2 Binary Tree Searching: Implement BST insert, search and delete with tests.
- Work the exercises (8 picked): Start with Ex 1, Ex 3, Ex 10; 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 49 exercises, rated 15 to M47, and Knuth marks 12 of them with the triangle for recommended. Implement Algorithms T and D, then check exercises 13 and 16 empirically before proving them. The optimum-tree exercises (22 to 33) pair well with coding Algorithm K. 29 and 48 are research-level or open.

Worth your time:

- 1 (rated 15): Make tree insertion handle the empty tree.
- 3 (rated 20, recommended): Can a sentinel speed up tree search the way it sped up sequential search?
- 10 (rated 22, recommended): Keep a search tree efficient on nonrandom input by making it look random.
- 14 (rated 22, recommended): Show the extra deletion step never lengthens paths, and find a case where it helps.
- 16 (rated 25, recommended): Is deletion commutative? Experiment first, then prove.
- 13 (rated M23, recommended): Does deleting the root keep a random tree random?
- 23 (rated M23, recommended): Find an optimum search tree for a skewed weight set without a computer.
- 45 (rated 30, recommended): Make the Garsia-Wachs algorithm run in n log n time. The stretch.

## Why it matters {#why}

BSTs are the basis of ordered maps. The optimal BST algorithm is a classic dynamic programming example.

## Before you start {#before}

- 2.3 Trees
- 6.2.1 Searching an Ordered Table

## How to approach it {#approach}

Implement BST insert, search and delete with tests. Then implement the optimal BST dynamic program and check it on a small set of words with frequencies.

## Common traps {#traps}

- Deletion of a node with two children is the classic bug spot.

## Links {#links}

- [Knuth's TAOCP page (editions, errata, MIX/MMIX)](https://www-cs-faculty.stanford.edu/~knuth/taocp.html)
- [Vol 3 errata (plain text, from Knuth)](https://www-cs-faculty.stanford.edu/~knuth/err3.textxt)
- [Wikipedia: Binary search tree](https://en.wikipedia.org/wiki/Binary_search_tree)
- [Wikipedia: Optimal binary search tree](https://en.wikipedia.org/wiki/Optimal_binary_search_tree)

---

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