Collision Resolution Techniques
Separate Chaining vs Open Addressing: Linear Probing (primary clustering), Quadratic Probing, and Double Hashing.
Reinforce your mental model: run, pause, and inspect live pointers with our interactive visualizer:
Topics Covered:
38. Separate Chaining (Open Hashing) • 39. Open Addressing (Closed Hashing) & The Deletion Dilemma • 40. Linear Probing & Primary Clustering • Quadratic Probing & Secondary Clustering • Double Hashing & Permutation Uniformity
Because the universe of possible search keys vastly exceeds the physical capacity of any hash table, collisions are mathematically unavoidable. An effective hash table is therefore defined by the resilience and efficiency of its collision resolution mechanism. This chapter explores the two dominant architectural paradigms: Separate Chaining (storing colliding elements in external node structures) and Open Addressing (probing for open slots directly within the primary array). We analyze probe sequence mechanics, the TOMBSTONE deletion state machine, primary and secondary clustering phenomena, and coprimality constraints in double hashing.
Learning Objectives
#- Contrast the physical memory layouts, cache performance, and load factor tolerances of Separate Chaining versus Open Addressing.
- Formulate the Open Addressing deletion dilemma and implement the
TOMBSTONEsentinel protocol to preserve probe continuity. - Diagnose the physical causes of Primary Clustering in Linear Probing and Secondary Clustering in Quadratic Probing.
- Implement Double Hashing and prove why the step function must be coprime to table capacity to guarantee a complete permutation of slots.
- Determine optimal collision resolution strategies based on payload size, memory constraints, and hardware cache considerations.
Topic 38: Separate Chaining (Open Hashing)
#1. Conceptual Architecture & Bucket Chains
In Separate Chaining, the hash table is an array of pointers (or bucket heads). Each slot points to an external linked list (or self-balancing binary search tree) containing all key-value entries that hashed to ().
+-----------------------------------------------------------------------------------+
| SEPARATE CHAINING BUCKET LAYOUT |
| |
| Slot 0 ----> NULL |
| Slot 1 ----> [ "Apple", $2 | * ] ----> [ "Peach", $4 | NULL ] (Collision chain) |
| Slot 2 ----> NULL |
| Slot 3 ----> [ "Banana", $1 | * ] ---> [ "Grape", $5 | * ] ---> [ "Berry", $6 ] |
| Slot 4 ----> [ "Mango", $3 | NULL ] |
+-----------------------------------------------------------------------------------+Interactive Simulations:
Observe bucket node insertions live in the Interactive Separate Chaining Visualizer.
Bucket Allocation Mapping
| Slot Index | Head Pointer State | Chain Length | Stored Keys in Bucket Chain | Traversal Cost |
|---|---|---|---|---|
0 | NULL | None (Vacant slot) | (Immediate miss) | |
1 | 0x10A0 | ("Apple", $2) -> ("Peach", $4) | hops | |
2 | NULL | None (Vacant slot) | (Immediate miss) | |
3 | 0x2500 | ("Banana", $1) -> ("Grape", $5) -> ("Berry", $6) | hops | |
4 | 0x3800 | ("Mango", $3) | hop |
2. Asymptotic Bounds Under SUHA
#Under the Simple Uniform Hashing Assumption (SUHA), keys are distributed uniformly across slots. The expected number of keys in any chain is exactly the load factor:
- Unsuccessful Search Cost:
The algorithm hashes key to slot and scans the entire chain to the end (NULL): - Successful Search Cost:
The target key is equally likely to be anywhere in the chain. On average, the search scans half the chain plus the initial slot access: - Worst-Case Degradation:
If an adversarial workload hashes all keys to the same bucket, the table degrades to a single linked list with search time.- Production Defense (Treeification): In Java 8+, if a single bucket chain exceeds nodes and table size , the linked list is converted into a Red-Black tree, guaranteeing worst-case search in .
Topic 39: Open Addressing & The Deletion Dilemma
#1. Conceptual Architecture & In-Place Storage
In Open Addressing, all keys reside directly inside the primary table array. No external pointers or heap nodes are allocated.
- Every slot holds either a single key-value entry or is vacant.
- The load factor can never exceed .
- When a collision occurs at initial slot , the algorithm probes a deterministic sequence of alternative slots until an empty slot is discovered:
2. The Deletion Dilemma: The TOMBSTONE State Machine
#In open addressing, simply setting a deleted slot to EMPTY corrupts subsequent search operations by prematurely terminating valid probe chains.
Failure Scenario (Linear Probing, ):
- Insert Key A: Stored at
Slot 2. - Insert Key B: Collision at
Slot 2! ProbesSlot 3(free). Stored atSlot 3. - Delete Key A: If
Slot 2is reset toEMPTY: - Search for Key B:
- Compute .
- Inspect
Slot 2. It isEMPTY! - Standard open addressing terminates search on the first
EMPTYslot. - False Negative: The table incorrectly reports that Key B does not exist, even though it sits at
Slot 3!
Search Path Severed:
[ Slot 2: EMPTY ] <--- Search halts here! Does not check Slot 3!
[ Slot 3: Key B ] <--- Key B is orphaned and unreachable!The TOMBSTONE (DELETED) Solution
Instead of clearing the slot to EMPTY, mark it with a permanent sentinel state: TOMBSTONE.
| Table Operation | Behavior Upon Encountering EMPTY | Behavior Upon Encountering TOMBSTONE |
|---|---|---|
| Search() | Halt and return "Not Found" (Chain ends) | Continue probing forward to next slot |
| Insert() | Claim slot and store entry | Claim slot (overwrites tombstone) |
| Delete() | Key does not exist; return false | Continue probing until key is found |
Topic 40: Probing Strategies: Linear, Quadratic & Double Hashing
#1. Linear Probing & Primary Clustering
#Linear Probing checks consecutive array slots one-by-one:
Interactive Simulation:
Step through sequential probe collision checks in the Interactive Linear Probing Visualizer.
The Primary Clustering Failure Mode:
Occupied slots merge into long unbroken contiguous chains called primary clusters. Once a cluster forms, any key whose initial hash falls anywhere within the cluster must traverse to the very end of the cluster to find a free slot, expanding the cluster further.
Linear Probing Step-by-Step Trace (, , Keys: )
| Key Inserted | Initial | Probe 0 () | Probe 1 () | Probe 2 () | Probe 3 () | Slot Assigned | Resulting Table State |
|---|---|---|---|---|---|---|---|
10 | Slot 3 (Free) | — | — | — | Slot 3 | [_, _, _, 10, _, _, _] | |
17 | Slot 3 (Taken) | Slot 4 (Free) | — | — | Slot 4 | [_, _, _, 10, 17, _, _] | |
24 | Slot 3 (Taken) | Slot 4 (Taken) | Slot 5 (Free) | — | Slot 5 | [_, _, _, 10, 17, 24, _] | |
31 | Slot 3 (Taken) | Slot 4 (Taken) | Slot 5 (Taken) | Slot 6 (Free) | Slot 6 | [_, _, _, 10, 17, 24, 31] |
Every single key collided at slot 3, creating a massive 4-element cluster spanning slots 3 through 6!
2. Quadratic Probing & Secondary Clustering
#Quadratic Probing replaces the linear step with a quadratic polynomial in :
A standard formulation is , yielding offsets . This allows the probe sequence to jump rapidly over contiguous clusters.
Secondary Clustering:
While Quadratic Probing eliminates primary clusters, keys that share the exact same initial hash () will trace identical quadratic probe sequences. This milder phenomenon is called Secondary Clustering.
Table Coverage Theorem:
If is a prime number and the load factor satisfies:
3. Double Hashing & Permutation Uniformity
#Double Hashing uses two independent hash functions and to generate a pseudo-random probe sequence unique to each individual key:
- determines the Starting Slot.
- determines the Step Stride.
Because the step size depends on the key value , two keys that collide at will almost certainly have different step strides (), completely eliminating both primary and secondary clustering!
Crucial Invariants for :
- must never evaluate to 0 (). If it were zero, the probe sequence would loop endlessly at .
- must be coprime to (). If they share a common factor , the sequence visits only slots rather than the entire table.
Canonical Double Hashing Equations (Prime ):
4. Comprehensive Architectural Comparison
#| Strategy | Primary Clustering | Secondary Clustering | Cache Line Performance | Max Viable Load Factor () | Pointer Memory Overhead |
|---|---|---|---|---|---|
| Separate Chaining | None | None | Poor (chasing heap pointers) | (Unlimited) | Yes ( / node) |
| Linear Probing | Severe | None | Optimal (sequential reads) | None () | |
| Quadratic Probing | None | Mild | Moderate | None () | |
| Double Hashing | None | None | Good | None () |
5. Key Takeaways
#- Chaining vs. Open Addressing: Chaining uses external linked lists with memory overhead; Open Addressing stores all keys inside the primary array and requires .
- TOMBSTONE Necessity: Open Addressing must mark deleted slots with
TOMBSTONEto prevent search chains from severing prematurely. - Primary Clustering: Linear probing produces contiguous clumps of occupied slots, degrading average search time.
- Double Hashing Superiority: Using a key-dependent step size coprime to prime yields independent probe permutations, eliminating clustering.
Academic Attribution & References
#- Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2022). Introduction to Algorithms (4th ed.), Chapter 11: Hash Tables. MIT Press.
- Knuth, D. E. (1998). The Art of Computer Programming, Volume 3: Sorting and Searching (2nd ed.), Section 6.4: Hashing. Addison-Wesley.
- Sedgewick, R., & Wayne, K. (2011). Algorithms (4th ed.), Section 3.4: Hash Tables. Addison-Wesley.