Data Structures · Visualization
Cuckoo Hashing: Lookup & Delete
Cuckoo Hashing
Lookup is beautifully boring: check slot h1, then slot h2 — found or not, in exactly two probes. Time: O(1) worst case, always ≤ 2 probes. Space: O(1) extra.
Big-O: Worst-case O(1) lookup in ≤ 2 probes.
Cuckoo Hashing: Lookup & Delete
Cuckoo HashingLookup is beautifully boring: check slot h1, then slot h2 — found or not, in exactly two probes. Deletion just clears the occupied slot (no tombstones, no chains to repair, unlike open addressing). Try your own keys below and count the probes.
How Lookup & Delete Works
- Compute h1, check table 1 — match means found.
- Compute h2, check table 2 — match means found.
- Neither matches → definitely absent (no false answers, ever).
- Delete: clear whichever slot matched; nothing else moves.
Lookup & Delete Worked Example
Input: Lookup 'cat' with Table1[2]='emu', Table2[1]='dog', Table2[4]='cat'
- h1('cat') → Table1[2] holds 'emu' → miss.
- h2('cat') → Table2[4] holds 'cat' → hit.
- Delete clears Table2[4]; tables otherwise untouched.
- Lookup 'owl' misses both slots → absent, proven in 2 probes.
Output: 'cat' found at Table2[4] in 2 probes; 'owl' absent in 2 probes
Press ▶ Run to watch it step by step.
def lookup(t1, t2, key):
if t1[h1(key)] == key: return (1, h1(key))
if t2[h2(key)] == key: return (2, h2(key))
return None # definitely absent — 2 probes max
# example: lookupBehind 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.
Lookup & Delete Time & Space Complexity
When to Use Lookup & Delete
- Membership tests with hard real-time deadlines
- Teaching why two choices beat one (power of two choices)
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.