This is the worked-examples companion to the parent open-addressing note. The parent gave you the three probe formulas and one example each. Here we hunt down every case class open addressing can throw at you — every collision pattern, every degenerate table, every deletion trap — and work each one to the last arithmetic step.
Before we start, one reminder of the machinery we are about to use constantly:
Every problem this topic can throw at you is one of the case classes below. Read the matrix first as a checklist — then each worked example is tagged with the cell(s) it fills, and together they cover the whole grid. If your viewer does not render tables, the same list is spelled out beneath it.
#
Case class
What makes it special
Example
A
No collision
home slot is empty, i=0 done
Ex 1
B
Single collision
one probe needed
Ex 1, 2
C
Cluster crawl (linear)
long contiguous run of full slots
Ex 2
D
Wrap-around
probe passes slot m−1 and loops to 0
Ex 3
E
Quadratic escape
jump skips past a cluster
Ex 4
F
Quadratic failure
free slot exists but is unreachable
Ex 5
G
Double hashing, same home
two keys, same h1, different h2
Ex 6
H
Double hashing, h2=0 trap
degenerate step size
Ex 6
I
Deletion + tombstone (search & reuse)
search crosses / insert reuses a deleted slot
Ex 7
J
Load-factor / limiting value
probe cost as α→1
Ex 8
K
Word problem (real world)
translate a story into probes
Ex 9
L
Exam twist
count total probes / compare schemes
Ex 10
Same list, plainly (in case the table above does not render): A = no collision; B = one collision; C = linear cluster crawl; D = wrap-around past the end; E = quadratic jump over a cluster; F = quadratic cannot reach a free slot; G = double hashing splits keys with the same home; H = the h2=0 infinite-loop trap; I = deletion needs a tombstone (both for searching past it and for reusing it); J = load factor pushing probe cost to infinity; K = a real-world story problem; L = an exam-style "count and compare" twist.
We use one small table for most examples so you can see the state build up:
m=11,h1(k)=kmod11.
Why m=11? Because 11 is prime, which (as the parent note stressed and Prime table sizes explains) is exactly the condition that makes quadratic and double hashing behave. We will break that rule on purpose in Ex 5 to watch it fail.
A cluster is a run of already-full slots with no gap between them. Look at figure s01: the blue slots 1,2,3 form one such run, and the orange slot 4 is a new key that hit inside the run and got dragged to its far end — extending the cluster by one. That growth is what we mean by "clustering is live": each new colliding key makes the run longer, so the next colliding key must crawl even further.
Figure s01 (below): linear probing on m=11. Blue = keys 12,23,34 already placed in slots 1,2,3; the bracket marks the full contiguous cluster; the orange arrow shows key 45 being dragged to slot 4 at the cluster's end.
What if the home slot is near the top of the array and the cluster runs off the end? The modm loops us back to slot 0. Never treat the array as having an "end" — it is a ring.
Figure s02 (below): the ring. Blue slots 9,10 are full; the green arrow shows a new key with home 9 probing 9→10→ wrapping back to slot 0; the dashed line reminds you that "one past slot 10" is slot 0.
Quadratic probing changes the offset to i2: the steps are 0,1,4,9,16,…. Small i still moves gently, but the jumps grow fast, letting a key leap over a cluster.
Figure s03 (below): quadratic escape. Blue slots 1,2,3 are a full cluster. The gray arrow is the tiny i=1 step (+1) landing on slot 2; the green arc is the i=2 step (+4) that vaults from home slot 1 clear over slots 3,4 into the green slot 5.
Double hashing makes the step size itself depend on the key via a second hash h2(k). Two keys that collide at home now walk different routes.
We use h2(k)=1+(kmod10) on our m=11 table. Why the "1+"? So the step is never 0 — a step of 0 would probe the same slot forever (cell H, the trap). Why mod10 i.e. mod(m−1)? To keep h2 in 1…10, and since 11 is prime, every value 1…10 is coprime to 11, guaranteeing the probe visits all slots.
Figure s04 (below): diverging paths. Gray slot 1 is the shared home. The blue arc shows key 1 (step h2=2) landing in slot 3; the orange arc shows key 12 (step h2=3) landing in slot 4 — same home, different destinations, no secondary clustering.