Data Structures Β· Visualization
Hash Table: Collision Handling (Open Addressing)
Hash Table
Open addressing resolves collisions by probing for the next available slot within the array itself (no extra lists), using a probing sequence such as linear probing, quadratic probing, or double hashing until an empty slot is found. Time: Average O(1) with low load factor, degrades toward O(n) as the table fills up. Space: O(n).
Big-O: Average O(1) per operation; worst case O(n) on collisions.
Hash Table: Collision Handling (Open Addressing)
Hash TableOpen addressing resolves collisions by probing for the next available slot within the array itself (no extra lists), using a probing sequence such as linear probing, quadratic probing, or double hashing until an empty slot is found.
How Collision Handling (Open Addressing) Works
- Compute the initial slot: index = hash(key) % size.
- If that slot is occupied by a different key, apply the probe function to get the next candidate slot (e.g. linear: index+1, index+2, ...).
- Repeat probing until an empty slot (or the key itself, for updates) is found.
- For lookups, probe the same sequence until the key is found or an empty slot signals 'not present'.
- Deletions need special 'tombstone' markers so probing sequences aren't broken for later lookups.
Collision Handling (Open Addressing) Worked Example
Input: Insert 'dog' and 'god' which both hash to slot 2 in a table of size 7, using linear probing
- hash('dog') % 7 = 2 β slot 2 empty β place 'dog' at 2
- hash('god') % 7 = 2 β slot 2 occupied β probe slot 3 β empty β place 'god' at 3
- Lookup 'god': check slot 2 ('dog', no match) β check slot 3 ('god', match)
Output: 'dog' at slot 2, 'god' at slot 3; lookup takes 2 probes
Press βΆ Run to watch it step by step.
# Hash map: key -> value, O(1) average
scores = {}
scores["alice"] = 90 # insert
v = scores.get("bob", 0) # get with default
del scores["alice"] # delete
if "bob" in scores: # membership
print("present")
# example: openaddr key=dogBehind the Scenes Execution
Press βΆ Run in the visualizer β the call stack, registers and memory will replay here in sync with the code, line by line.
Collision Handling (Open Addressing) Time & Space Complexity
When to Use Collision Handling (Open Addressing)
- Cache-friendly hash maps (Python dict, Rust HashMap)
- Memory-constrained embedded systems avoiding pointer overhead
Recommended resourcesAffiliate links Β· may earn us a commission
Recommended for learners
Ready for the next step?
See the same ideas in action β visualize the algorithms that operate on these structures, or take a guided course.