Skip to content
Computing Medium #cuckoo-hashing#hash-table#eviction

Cuckoo Hashing

Each key has two homes. On collision the resident is evicted to its alternate slot, recursively.

A free, animated cuckoo hashing you can read here or embed on any website, from Scrollchart.

Cuckoo Hashing

Cuckoo HashingTwo tables, two hash functions: worst-case O(1) lookup via exactly two probesTable 1 (h1)Table 2 (h2)[0][0][1][1][2][2][3][3][4][4][5][5]K4K3K1K2K1 evictedto its h2 slotinsert K4h1(K4)=0Key propertiesLookupO(1) worst-case: check T1[h1(k)],then T2[h2(k)]. Never more.InsertO(1) amortized; eviction chainresolves in expected O(1) steps.DeleteO(1): locate slot, clear it.LoadMax safe load factor ~50% pertable; cycle detected at ~100%.RehashOn cycle: choose new h1/h2 andrebuild. Rare in practice.Cuckoo hashing eliminates worst-case probe chains: every key lives in exactly one of two known slots

Available in: PortuguêsItaliano

Two hash tables. An insert hashes to two slots; if both are full the occupant of slot 1 is evicted to its alternate, possibly cascading. Worst-case lookup is O(1) (just two probes).

Good for

  • High-performance hashmap deep-dives comparing worst-case vs amortized lookup guarantees
  • Network systems articles where O(1) hard-bounded lookup latency is required
  • Comparison pieces contrasting cuckoo hashing with Robin Hood and linear probing

Source & accuracy

This cuckoo hashing is an editorial illustration built to represent the concept accurately. Where it shows figures, they are typical or representative values chosen to make the relationship clear, not a single underlying dataset. The diagram and its explainer are reviewed and maintained centrally, and updated over time as understanding improves.

Two homes per key with recursive displacement

Cuckoo hashing assigns each key two possible bucket positions, computed by two independent hash functions h1(key) and h2(key). On insert, the key goes into one of its two homes if vacant. If both are occupied, the algorithm 'evicts' the current resident and relocates it to its other home, recursively evicting as needed. This chaining of displacements resembles a cuckoo pushing other birds out of their nests.

The name comes from this eviction behavior. If done carefully with cycle detection, the algorithm guarantees O(1) lookups: the key is either at h1(key) or h2(key). Insertions are amortized O(1) as long as the load factor stays below a threshold, typically around 0.5.

Guarantees and failure scenarios

If the insertion process enters an infinite loop (a displacement cycle with no resolution), the table must be resized and all entries rehashed with new hash functions. This rehashing is expensive but rare if load factors are kept low and hash functions are chosen carefully. A load factor near 0.5 typically keeps cycles infrequent.

Cuckoo hashing offers worst-case O(1) lookups, which regular chaining hash tables cannot provide (they can degrade to O(n) on collision chains). This makes cuckoo hashing valuable for latency-critical applications. However, its insertion overhead and strict load-factor management make it less convenient than simpler alternatives like linear probing or chaining for general use.

Embed this diagram

Add this animated cuckoo hashing to your own site. Copy one line of HTML, or use the embed builder for theme and sizing options.

Reference

What this is
A free, embeddable, animated cuckoo hashing for any website.
Who uses it
Developer blogs, CS educators.
How to embed
Copy one line of HTML. No signup. No watermark. Works in WordPress, Webflow, Ghost, Substack, plain HTML.
File size
iframe embed, ~80 KB gzipped (loads on demand, does not block your page paint).
License
Free forever. Editorial explainer text included; updated centrally over time.

Embed format options

Copy the universal HTML snippet, the WordPress shortcode, or an iframe fallback - see the WordPress plugin page for details. Any format keeps the same Core Web Vitals profile and the same explainer text.

Embed snippet
<div data-scrollchart="cuckoo-hashing" data-scrollchart-v="1"></div>
<script src="https://scrollchart.com/embed.js" async></script>

Frequently asked questions

Where can I get a free animated "Cuckoo Hashing" for my website?
Scrollchart provides "Cuckoo Hashing" as a free, embeddable animated diagram you can add to any website with one line of HTML. No signup is required and there is no watermark. The diagram and its explainer text are served from scrollchart.com, so the embed stays current without any maintenance on your end.
How do I embed a cuckoo hashing in a developer or tech blog?
Copy the one-line snippet from the Scrollchart diagram page and paste it into your post HTML. It works in any static site generator, CMS, or hand-coded HTML page. The embed is a thin loader, not an iframe, so the content is fully in your DOM.