Advanced Topic 47 of 52 Data Structures
Cuckoo Hashing
Hashing scheme with two tables guaranteeing constant lookup.
How it works
In cuckoo hashing each key can live in one of two positions given by two hash functions, often in two tables. Lookup checks at most two slots, giving worst-case O(1) time. Insertion places the key in one slot, evicting any occupant to its alternative slot, possibly cascading; if a long cycle is detected, the table is rehashed with new hash functions.
Where it is used
Network hardware lookup tables, high-performance caches, in-memory databases and packet-processing pipelines that need guaranteed constant lookups use cuckoo hashing.
Common pitfall
Load factors must stay below roughly 50 percent for two tables, or higher with more choices or buckets, otherwise insertions fail. Insert cost is unpredictable, with occasional full rehashes. Hash functions must be independent. Use stashes or bucketed variants to handle rare failures gracefully.
Where it fits in the course
Cuckoo Hashing is topic 47 of 52 in Data Structures, rated Advanced. It follows Van Emde Boas Trees. The next topic is Count-Min Sketch.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Data Structures quiz.
- Explore the Hash Table visualizer: Hash function, buckets and chaining collisions.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Data Structures quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Cuckoo Hashing?
Where do people use Cuckoo Hashing?
What is the most common mistake with Cuckoo Hashing?
What should I learn before this topic?
How can I practice it?
Is Cuckoo Hashing hard to learn?
How long does it take to learn Cuckoo Hashing?
Which topics are related to Cuckoo Hashing?
What should I study after Cuckoo Hashing?
Related topics
- Van Emde Boas Trees (Data Structures)
- Count-Min Sketch (Data Structures)
- Fibonacci Heaps (Data Structures)
- HyperLogLog (Data Structures)
- Passwords and Hashing (Security & Cryptography)
- Consistent Hashing (Distributed Systems & Cloud)