Cuckoo Hashing Flashcards

1
Q

Cuckoo Hashing

A

Another way to resolve collisions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Idea

A

The cuckoo bird
o Shares a nest with other species o … then kicks the other species out
§ Same idea with cuckoo hashing

§ When we insert k1 we kick out what occupies the bucket, let’s say k2
§Then, k2 finds a new bucket

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Implementation

A

§ We have two hash tables T1 and T2

§ Collision strategy
o Each hash table has a hash function h1 and h2
o We prefer T1, but if we have to move we’ll go to T2
o If we are in T2 and have to move, we’ll go to T1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why two tables?

A

o Simple to visualize and implement
-Two hash functions h1 and h2 (one per table)

§ One table works just as well
-Using two hash functions h1 and h2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Cuckoo Hashing running time

A
§ Cuckoo hashing guarantees
 o O(1) search, O(1) insert

§ Remember: other hashing strategies can’t guarantees this!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Previous Collision Strategies

A

§Open addressing:
o Advantages: Simplicity and fixed memory usage
o Disadvantages:
-Deletions are problematic. Hence, chaining is more common when keys have to be deleted

§ Chaining:
o Advantages: Simplicity and fixed memory usage
-Simpler insertion and removal
o Disadvantages: Memory overhead is large if entries are small

How well did you know this?
1
Not at all
2
3
4
5
Perfectly