Wait, What?
A hash table can become faster by keeping everything in one crowded array—provided you understand exactly how collisions are allowed to move.
Beginners often meet hash tables as a simple promise: compute a hash, jump to a slot, and get near-constant-time lookup. Professional hash tables are more interesting. They must decide what happens when two keys want the same place, how deletion preserves future searches, how much crowding is safe, how memory layout affects the processor, and what assumptions are hiding inside the word “average”.
This Learning Hall article owns one specific job: teaching open-addressing collision resolution from first trace to professional engineering judgement. It complements the existing general hash-table article rather than replacing it.
Quick Read
- Beginner: learn what a probe sequence is and why lookup must repeat the same sequence as insertion.
- Intermediate: understand tombstones, load factor, primary clustering and displacement.
- Advanced: compare Robin Hood hashing with cuckoo hashing and reason about expected versus worst-case behaviour.
- Professional: include cache locality, metadata, SIMD-friendly group probing, adversarial inputs, resizing policy and measured workload behaviour.
The One-Sentence Answer
An open-addressing hash table stores entries inside the table array itself and resolves collisions by following a deterministic or randomised sequence of alternative locations until the key is found, inserted, or proven absent.
1. Start With the Dictionary Contract
Before learning a collision strategy, state the operations the structure must support: find, insert, and usually erase. A correct implementation must preserve a simple but powerful search invariant: if a key is present, lookup must visit every location that insertion could have used before it is allowed to declare the key absent.
This is the first place to slow down. Ask the learner to predict the next slot before showing it. Programming-education research increasingly supports this kind of stepwise retrieval and self-explanation: retrieving the next problem-solving step before it is revealed can improve later problem solving, while code-tracing and self-explanation help learners focus on program state rather than syntax alone.
2. Linear Probing: The Smallest Useful Model
Suppose the table size is m and a key hashes to index h. Linear probing tries h, then h+1, h+2, and so on modulo m. The rule is easy. The reasoning is not.
probe(key, i) = (hash(key) + i) mod m
i = 0, 1, 2, ...
Trace a tiny table by hand. Mark each slot as EMPTY or OCCUPIED. Insert keys one at a time. Then search for a key that is present and one that is absent. The learner should discover the crucial rule: an EMPTY slot can terminate a search only if no deletion has broken the probe chain.
3. Why Deletion Needs Tombstones
If you simply turn a deleted slot back into EMPTY, you may cut a probe chain in half. A later key that was displaced beyond that slot becomes unreachable. The usual repair is a third state: DELETED, often called a tombstone. Search continues through a tombstone; insertion may reuse it.
That creates a second-order problem. Too many tombstones lengthen probes even when the live load is modest. Production tables therefore need a policy for rebuilding, compacting or resizing—not merely a correct delete operation.
4. Load Factor Is a Behavioural Variable, Not Decoration
The load factor α is the fraction of slots occupied by live entries. As α approaches 1, open addressing loses room to manoeuvre. Probe sequences get longer and insertions become more fragile. The important professional lesson is that complexity statements are conditional: expected constant-time operations rely on assumptions about hashing, load and resizing.
Linear probing also suffers from primary clustering. A run of occupied slots attracts future insertions that hash anywhere into or just before the run, causing the run to grow. This is an excellent point for a visual trace: do not tell the learner clustering exists; let them watch one cluster become self-reinforcing.
5. Robin Hood Hashing: Equalising Probe Displacement
Robin Hood hashing tracks how far an entry has travelled from its ideal position. During insertion, if the incoming key has travelled farther than the resident key, the incoming key takes the slot and the displaced resident continues probing. Informally, the key with the larger displacement “steals” the better position.
The learning objective is not the slogan. It is the invariant. Define probe distance precisely, trace a swap, and ask why the variance of successful-search lengths tends to shrink. Then explore early-termination rules that become possible when probe distances are monotone along a cluster under a particular implementation.
Do not turn Robin Hood into folklore. Modern analysis continues to refine what can and cannot be claimed for different probing schemes. A 2026 study of smoothed quadratic probing, for example, found surprising separations between Robin Hood and anti-Robin Hood orderings under that model. The professional habit is therefore: name the probing model before quoting its performance.
6. Cuckoo Hashing: Give Each Key More Than One Home
Cuckoo hashing changes the geometry. Instead of one probe sequence, a key has a small set of candidate locations, often two. Lookup checks those locations directly. Insertion may evict a resident key and move it to its alternative home, which may evict another key, creating an eviction chain.
The beginner trace is wonderfully concrete: two homes per key, one key arrives, one resident is kicked out, and the displaced key moves. The advanced question is what happens when the eviction path cycles or cannot find space. The answer may involve rehashing, rebuilding, a stash, bucketisation or a different insertion strategy.
Recent 2025–2026 research continues to improve high-load cuckoo hashing and insertion guarantees, which is a useful reminder that “cuckoo hashing” names a family rather than one frozen implementation.
7. Swiss-Table Ideas: Let Memory Layout Join the Algorithm
Abseil’s public Swiss-table design notes show a modern direction: keep compact metadata beside densely stored entries, split the hash into parts, and inspect groups of control bytes efficiently before touching full keys. The algorithmic lesson is larger than one library. On modern hardware, an operation’s cost is not described completely by counting abstract probes. Cache lines, branch prediction, vector instructions, metadata density and indirection matter.
This does not mean beginners should start with SIMD. It means professionals eventually need two models in their heads at once: the mathematical table and the machine that executes it.
8. Complexity: Say Exactly Which Guarantee You Mean
- Expected time: averages over a stated random model, usually hashing assumptions.
- Amortized time: averages cost across an operation sequence, such as occasional resizing.
- Worst-case time: bounds an individual operation regardless of luck.
- High-probability bound: says bad outcomes are unlikely under a specified model.
A learner who says “hash tables are O(1)” has not finished. A stronger statement is: “With suitable hashing and controlled load, this implementation has expected constant-time lookup; pathological collision patterns can still be much worse.”
9. Security and Adversarial Inputs
If keys can be chosen by an adversary who understands the hash function, collision behaviour can become a denial-of-service surface. Professional systems may use keyed or randomised hashing, limit work, change table strategies, or detect pathological behaviour. This is not a reason to frighten beginners; it is a reason to distinguish classroom randomness from hostile workloads.
10. A Learning Hall Practice Ladder
- Level 1 — Trace: insert five keys into a ten-slot linear-probing table.
- Level 2 — Predict: before each probe, state the next index and whether lookup may stop.
- Level 3 — Repair: delete a key incorrectly, find the broken lookup, then introduce tombstones.
- Level 4 — Explain: describe primary clustering without using the phrase “because collisions happen”.
- Level 5 — Compare: trace one Robin Hood insertion and one cuckoo insertion on the same keys.
- Level 6 — Measure: benchmark probe counts as load factor rises; do not measure only wall-clock time.
- Level 7 — Engineer: compare memory footprint, cache locality, deletion policy, rebuild cost and tail latency.
- Level 8 — Defend: state which probabilistic assumptions support each complexity claim.
11. Misconceptions to Catch Early
- A collision does not mean the hash function is “wrong”.
- An empty slot and a deleted slot do not necessarily mean the same thing.
- A lower average probe count does not automatically mean lower worst-case latency.
- Robin Hood hashing and cuckoo hashing solve collisions differently; neither is simply “better”.
- Open addressing is not automatically memory-efficient if resizing policy leaves large unused capacity.
- Benchmark results from one key distribution are not universal laws.
12. Professional Test Checklist
- Insert, find and erase at low and high load.
- Search for missing keys that terminate after long probe chains.
- Delete from the middle of a cluster.
- Force wrap-around at the end of the table.
- Trigger resize and verify every key remains reachable.
- Use poor hash distributions deliberately.
- Measure successful and unsuccessful lookup separately.
- Measure percentiles, not only averages, when latency matters.
13. Where This Connects Without Cannibalising
The existing Hash Tables article remains the canonical foundation for hashing, collisions, load factor and rehashing. This page goes deeper into the open-addressing branch. The existing Cache-Replacement, Load-Balancing and Database Join articles may use hashing ideas, but they own different system jobs. The Learning Hall connection is therefore additive: foundation → specialised collision strategy → machine-aware implementation.
14. Authoritative Reading
- Abseil Swiss Tables Design Notes — public design explanation of metadata-driven open addressing.
- Quadratic Probing Revisited: Smoothed Analysis and the Fall of Robin Hood — 2026 analysis showing why probing model matters.
- Fast Insertion for Bucketized Cuckoo Hashing — 2026 work on high-load cuckoo insertion.
Final Check
You understand modern open addressing when you can trace the exact probe path, explain why deletion preserves or breaks reachability, distinguish Robin Hood displacement from cuckoo eviction, state the probabilistic assumptions behind the performance claim, and connect the abstract algorithm to cache-conscious implementation choices.
