8.5 Open Addressing: Tombstones & Probe Bounds
💡 Core Intuition: The 3-Second Mental Model
🍳 The Everyday Analogy:
Suppose three friends book desks in sequence: Desk #5 is taken by Alice, Desk #6 is taken by Bob, so Carol spills onto Desk #0. If Bob checks out early and erases his nametag back to "Never Occupied" (EMPTY), anyone searching for Carol sees Desk #6 blank and quits before ever checking Desk #0! Leaving a "Checked Out — Keep Walking" sticky note (Tombstone) preserves the breadcrumb trail so downstream lookups never snap!
💻 Bridging to Computer Science:
Safe deletion inside any Open-Addressed hash table (Linear, Quadratic, or Double Hashing) demands three distinct slot states: EMPTY, OCCUPIED(k), and DELETED (Tombstone). Over time, stale tombstones accumulate and raise effective occupancy toward , pushing lookups down the CLRS asymptotic cliff unless reclaimed via periodic rehashing or Backward-Shift Deletion.
📑Table of Contents
🪦 Why Deleting to EMPTY Breaks Open Addressing
Suppose keys {19, 26, 33} all hash to slot [5] under , placing 19 -> [5], 26 -> [6], 33 -> [0]. Watch what happens when we delete 26:
The Three-State Slot Protocol (EMPTY, OCCUPIED, DELETED)
Every operation respects distinct transition rules:
delete(k): Probe until findingk; overwrite slot state withDELETED(neverEMPTY).search(k): Keep walking past bothOCCUPIEDmismatches ANDDELETEDtombstones; concludeNOT_FOUNDonly upon reaching a pristineEMPTYslot (or completing steps).insert(k): Keep probing past tombstones first (to verifykdoes not already sit further downstream!), recording the earliestDELETEDindex seen; once hittingEMPTY, writekinto that earliestDELETEDslot (or theEMPTYslot if no tombstone appeared)!
🔄 Effective Load Factor Bloat & Backward-Shift Deletion
Even when live elements sit low (25% full), accumulated tombstones inflate effective load factor:
Because search() keeps probing past every DELETED slot, stalls unsuccessful lookups just as badly as live keys! Production engines resolve tombstone bloat via two strategies:
- Tombstone-Aware Rehashing: Trigger rehash whenever
n + d > 0.70 * m(rebuilding clears allDELETEDback toEMPTY). - Backward-Shift Deletion (Tombstone-Free Linear / Robin Hood Probing): When deleting
[6], check if downstream neighbor[0]sits past its home slot (probe_dist > 0). If so, pull33one step backward into[6]and cleanly set[0] = EMPTY!
📊 CLRS Expected Probe Bounds Under Uniform Open Addressing
Under ideal Uniform Hashing (closely approximated by Double Hashing, , zero tombstones), CLRS proves two fundamental expected probe complexity theorems:
Why ? At each step of an unsuccessful search, you stop immediately on an EMPTY slot with probability (geometric trials with success rate ).
| Occupancy / Load Factor () | Unsuccessful Search () | Successful Search () | System Behavior |
|---|---|---|---|
| ( full) | probes | probes | Near-instant lookups |
| ( full) | probes | probes | Sweet spot for Quadratic & Linear probing |
| ( full) | probes | probes | Standard resize trigger () |
| ( full) | probes | probes | Rapidly rising probe tail latency |
| ( full) | probes | probes | Steep latency cliff begins |
| ( full) | probes | probes | Degrades toward linear scan |
🏭 Real-World Production Context
Tombstone Lifecycle & Load Guards in Production Hash Maps
Tombstone reclamation and incremental rehashing keep Open Addressing deterministic under heavy delete churn
CPython dict DKIX_DUMMY Sentinels
Compact Index Array- Python marks deleted hash-index slots DKIX_DUMMY (Tombstone) so surviving probe sequences remain intact.
- Rehashing automatically strips accumulated DUMMY slots back to DKIX_EMPTY on resize or shrink.
Rust SwissTable Ctrl Bytes (0xFE vs 0x80)
Abseil / Hashbrown- Stores 1-byte metadata tags per slot: 0x80 denotes EMPTY, 0xFE denotes DELETED (Tombstone).
- Matches 16 control bytes simultaneously in a single SSE2 instruction, reclaiming DELETED groups cleanly.
Backward-Shift Open Addressing
Robin Hood Hashing- Avoids Tombstone states entirely by shifting displaced downstream elements one slot toward their home buckets on delete.
- Maintains pristine probe variance over millions of rapid insert/delete transactions without tombstone leaks.
Redis Incremental Rehash Pacing
SLA Tail Latency Guard- Avoids multi-millisecond rehash freeze pauses by migrating 1 hash bucket lazily per read/write command.
- Monitors occupancy bounds continuously so lookup latencies never approach the 1/(1-alpha) asymptotic cliff.
📐 Numerical Applications & Worked Examples
- A Linear Probing hash table of capacity holds live keys and
DELETEDtombstones (100EMPTYslots left). Compute both the apparent load factor and the effective load factor , and estimate expected unsuccessful search probes (assuming uniform-like spacing of non-EMPTYslots). - An Open Addressed table running Double Hashing has slots and currently stores items () with zero tombstones. Compute the expected probe upper bounds for an unsuccessful search vs. a successful search ().
Step-by-Step Solution:
-
Tombstone Effective Load Bloat (
m = 1000,n = 250,d = 650):- Apparent Live Load Factor: (naively predicts ).
- Effective Probe Occupancy: Only pristine
EMPTYslots remain, so ! - Unsuccessful Probe Impact: Stopping probability is (and even worse under Linear Probing clustering!). Rehashing immediately clears all
650tombstones back toEMPTYand restores1.33-probe speed!
-
CLRS Probe Bounds at (
m = 1000,n = 750, zero tombstones):- Unsuccessful Search: .
- Successful Search: .
🎯 Exam & Interview Pitfall Check
- Why must
insert(k)NOT stop and overwrite the very firstDELETEDtombstone it encounters without continuing further?- Key
kmight already sit downstream past that tombstone! Stopping early would insert a duplicate key into the hash table. Always save the index of the firstDELETEDslot, continue probing until seeingk(update/return duplicate) orEMPTY, and only then insert into that saved tombstone!
- Key
- If a hash table stays
30%live with65%tombstones, why does deleting and reinserting keys still get slow over time?- Because
search()skips right pastDELETEDmarkers! Effective load factor is , inflating unsuccessful search cost to probes instead of probes.
- Because
- Why is Backward-Shift Deletion safe for Linear Probing yet problematic for Double Hashing?
- Linear Probing shifts every occupant monotonically along steps, making home-distance monotonic checks (
dist > 0) trivial. Under Double Hashing, different keys take completely different strides , so shifting another key backward+1violates its own probe sequence!
- Linear Probing shifts every occupant monotonically along steps, making home-distance monotonic checks (
- Rehashing Only When Live Size
n / m > 0.75: Under churn-heavy deletes,n / mstays0.20while(n + d) / mclimbs to0.98, causing silent query latency timeouts! Always checkoccupied + deleted(or tombstone ratio) before skipping a rehash. - Same-Size Tombstone Purge Optimization: When a rehash is triggered primarily by high
d(DELETED) whilenis still tiny (n <= 0.25 * m), rehash into a table of the SAME capacity (or shrinkm / 2) — stripping tombstones to zero without wasting RAM! - Forgetting Loop Termination at
mProbes: If a buggy open-addressed table temporarily hits0EMPTYslots (100%OCCUPIED+DELETED),search()stops only after trackingprobes < msteps rather than looping forever waiting forEMPTY!
🚀 Navigation & Next Steps
🎉 Congratulations! You have completed the entire CoreDose Data Structures curriculum — from memory layout, recursion, stacks, queues, and linked lists to balanced trees, graphs, DSU, and high-throughput hashing!
Never Study in Isolation. Join Binary Dose.
Connect with fellow engineers, clear conceptual doubts, and get 2 visual breakdowns & engineering mental models daily across our community channels.
Discord Community
Start at #welcome-and-rules, say hello in #general-chat, clear doubts, and collaborate with engineers worldwide.