TAOCP Vol 3: Sorting and Searching · Week 110

TAOCP 6.2.2 Binary Tree Searching

Updated

About 8 hours49 exercises, rated 15 to M47

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.

Flashcards 14 cards for Anki and AnkiMobile · all decks

Anki deck.tsv

This week's steps

3 steps
  1. Read §6.2.2 Binary Tree Searching

    Implement BST insert, search and delete with tests.

  2. Work the exercises (8 picked)

    Start with Ex 1, Ex 3, Ex 10; log what you solve below.

  3. 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.

Sign in to track this: tick each step off and it counts toward your week.

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

  • Exercise 115

    Make tree insertion handle the empty tree.

    Discuss

  • Exercise 320▶ Recommended

    Can a sentinel speed up tree search the way it sped up sequential search?

    Discuss

  • Exercise 1022▶ Recommended

    Keep a search tree efficient on nonrandom input by making it look random.

    Discuss

  • Exercise 13M23▶ Recommended

    Does deleting the root keep a random tree random?

    Discuss

  • Exercise 1422▶ Recommended

    Show the extra deletion step never lengthens paths, and find a case where it helps.

    Discuss

  • Exercise 1625▶ Recommended

    Is deletion commutative? Experiment first, then prove.

    Discuss

  • Exercise 23M23▶ Recommended

    Find an optimum search tree for a skewed weight set without a computer.

    Discuss

  • Exercise 4530▶ Recommended

    Make the Garsia-Wachs algorithm run in n log n time. The stretch.

    Discuss

Your log

Sign in to log the exercises you work: number, rating, how far you got.

Your notes

Only you

Sign in to keep private notes on this guide, in Markdown. They stay yours: never on your profile, and you can export them all.

Discussion

0 posts

Questions about the reading go here; each exercise has its own thread below. Hints over answers.

No posts yet. Ask a question or share a tip.

Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Exercise threads

One thread per exercise. Open one to ask for a nudge or check your thinking.

  • Exercise 115No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 320No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1022No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 13M23No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1422No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1625No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 23M23No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 4530No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Reference

Why it matters

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

Before you start
  • 2.3 Trees
  • 6.2.1 Searching an Ordered Table
How to approach it

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
  • Deletion of a node with two children is the classic bug spot.

Spot a mistake? Report it

Back to week 110