TAOCP Vol 3: Sorting and Searching · Week 115

TAOCP 6.4 Hashing (part 2)

Updated

About 9 hours78 exercises, rated 10 to M49

Summary

TAOCP 6.4 Hashing (part 2) covers the rest of the section (pages 533 to 549): deleting from open-addressed tables without breaking later searches, the starred analysis of expected probe counts for chaining, and more. Budget about 9 hours; do exercises 21, 65 and 42.

Part 2 covers the rest of the section (pages 533 to 549): deleting from open-addressed tables without breaking later searches, the starred analysis of expected probe counts for chaining, linear probing and double hashing as the table fills, hashing on external storage with buckets, a comparison of all the methods, and history.

Flashcards 15 cards for Anki and AnkiMobile · all decks

Anki deck.tsv

Step through at your own pace; the arrow keys work too.

Crafting Interpreters · Ch 20 · TAOCP 6.4 A hash table with linear probing Collisions probe to the next slot, deletions leave tombstones, and a full enough table doubles. Type your own keys.

find figcount 4live 3capacity 8load 0.50

  1. 0empty
  2. 1kiwihome
  3. 2empty
  4. 3empty
  5. 4empty
  6. 5tombstone
  7. 6fighome 5
  8. 7applehome

Slot 6 holds "fig": found, because probing went on past the tombstone at slot 5.

This week's steps

3 steps
  1. Read §6.4 Hashing (part 2)

    Compare this with your clox hash table from chapter 20: tombstones, load factor, linear probing.

  2. Work the exercises (8 picked)

    Start with Ex 21, Ex 65, Ex 42; 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

Section 6.4 has 78 exercises (one set for both weeks), rated 10 to M49, and Knuth marks 15 of them with the triangle for recommended. This week covers pages 533 to 549: deletions, the analysis of the algorithms, external searching, the comparison of methods and the history. The matching exercises are 21 to 65 and 67 to 71 (50 exercises, 8 recommended: 21, 23, 33, 34, 37, 42, 48, 65). Most are M or HM analysis; pick a few rather than grinding through. 57, 60 and 62 are open, and many in the 40s are research-level.

Worth your time

  • Exercise 2120▶ Recommended

    After marking a record deleted, should the item count go down?

    Discuss

  • Exercise 2333▶ Recommended

    Design deletion for coalesced chaining, analogous to linear-probing deletion.

    Discuss

  • Exercise 29M21

    The parking problem: linear probing told as a story about cars.

    Discuss

  • Exercise 33M23▶ Recommended

    Why the classic linear probing estimate is only an approximation.

    Discuss

  • Exercise 34M23▶ Recommended

    List-length distribution and probe counts for separate chaining.

    Discuss

  • Exercise 37M29▶ Recommended

    Variance of successful search cost under separate chaining. The stretch.

    Discuss

  • Exercise 42M20▶ Recommended

    Probability that chained hashing finds a free slot immediately.

    Discuss

  • Exercise 6520▶ Recommended

    How to store variable-length keys in a hash table.

    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 2120No 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 2333No 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 29M21No 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 33M23No 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 34M23No 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 37M29No 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 42M20No 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 6520No 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

Open addressing with linear probing is what many modern high-performance hash tables use. Knuth's linear probing analysis is historically the start of the field of algorithm analysis.

Before you start
  • 6.4 Hashing (part 1)
How to approach it

Compare this with your clox hash table from chapter 20: tombstones, load factor, linear probing. Measure probe counts at load factors 0.5, 0.75 and 0.9 and compare to Knuth's formulas.

Common traps
  • Deleting by just clearing a slot breaks later searches. Tombstones or Knuth's deletion algorithm fix this.
  • Letting the load factor get close to 1 with linear probing.

Spot a mistake? Report it

Back to week 115