3.3.6 · D3Hashing

Worked examples — Load factor — when to resize, rehashing cost

3,727 words17 min readBack to topic

This page hammers the load-factor and rehashing ideas from the parent note through every case that can appear. Before each answer you'll see a Forecast: line — pause and guess the number first. Guessing then checking is how the ideas stick.

Everything here uses only three symbols from the parent:

  • = number of keys currently stored.
  • = number of buckets (slots) the table has.
  • = the load factor (how full the table is).

One more piece of notation we will need in Ex 5:

Two flavours of "search cost" appear throughout:

  • Unsuccessful search — the key is not present; you scan/probe until you prove it's absent.
  • Successful search — the key is present; you stop as soon as you find it, so on average you do a little less work.

If any of those feel shaky, reread the parent and the prerequisites Separate Chaining, Open Addressing, Amortized Analysis, and Dynamic Arrays first.


The scenario matrix

Every question this topic can throw at you falls into one of these case classes. The worked examples below are labelled with the cell they cover, and together they hit all of them.

# Case class What makes it tricky Covered by
A Chaining, normal () cost is , linear and gentle Ex 1
B Open addressing, normal () cost is , still tame Ex 2
C Open addressing, the cliff () cost explodes — the danger zone Ex 3
D Degenerate: (empty table) limiting value, formulas must not break Ex 4
E Degenerate: in open addressing (full) division by zero — undefined, table is full Ex 4
F Amortized doubling — count total rehash work geometric series Ex 5
G The wrong growth (additive) — why it's contrast case, catastrophe Ex 6
H Word problem: pre-sizing for a target pick from and Ex 7
I Exam twist: hysteresis / thrashing grow↔shrink near one boundary Ex 8
J Chaining vs open addressing at same why they resize at different points Ex 9
K Successful vs unsuccessful search successful is a bit cheaper — a symmetric case Ex 10
L Chaining overload more keys than buckets; still holds Ex 11












Recall Quick self-test (reveal after guessing)

Chaining at , expected unsuccessful search cost? ::: . Open addressing at , expected probes (idealised)? ::: . Open addressing at , expected probes (idealised)? ::: . Both formulas at ? ::: Both give . Open-addressing formula at ? ::: Undefined / (table full, search never terminates). What does mean (vs )? ::: is the chosen policy threshold we refuse to exceed; is the table's actual current fullness. Total rehash moves inserting 16 keys with doubling from size 1? ::: . Total work (cheap inserts + rehash) for those 16 keys? ::: . Additive-4 growth (start capacity 4), total moves for 16 keys? ::: , scaling as . Minimum for 30000 keys at ? ::: . Chaining vs open addressing at (unsuccessful)? ::: vs . Chaining successful search at ? ::: . Open-addressing successful search at ? ::: . Why is only an idealised bound? ::: It assumes uniform hashing; real schemes like linear probing cluster and cost more. Chaining at (overloaded), expected unsuccessful cost? ::: ; the formula holds for .