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 Hashing

Lookup 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

  1. Compute h1, check table 1 — match means found.
  2. Compute h2, check table 2 — match means found.
  3. Neither matches → definitely absent (no false answers, ever).
  4. 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'

  1. h1('cat') → Table1[2] holds 'emu' → miss.
  2. h2('cat') → Table2[4] holds 'cat' → hit.
  3. Delete clears Table2[4]; tables otherwise untouched.
  4. Lookup 'owl' misses both slots → absent, proven in 2 probes.

Output: 'cat' found at Table2[4] in 2 probes; 'owl' absent in 2 probes

Try your own input
Cuckoo: Introduction
Two homes per key — worst-case O(1) lookup in ≤ 2 probes.
Table 1 · h1
·
0
·
1
·
2
·
3
·
4
Table 2 · h2
·
0
·
1
·
2
·
3
·
4
Probed/evicted slot Occupied
Cuckoo: Introduction
Press ▶ Run to watch it step by step.
Python · Cuckoo Hashing in Code
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: lookup
Input: Lookup 'cat' with Table1[2]='emu', Table2[1]='dog', Table2[4]='cat'

Behind 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

TimeO(1) worst case, always ≤ 2 probes
SpaceO(1) extra

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

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Ready for the next step?

See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.