Professional Documents
Culture Documents
Exercises For Advanced Algorithms WS 20/21: Institut Für Informatik Abteilung 1
Exercises For Advanced Algorithms WS 20/21: Institut Für Informatik Abteilung 1
Exercises for
Excercise Sheet 6
Advanced Algorithms Discussion:
WS 20/21 CW 52/CW 01
and m = 9.
h 0 1 2 3 4 5 6 7 8
key
name Kai P ia Ada
a) Calculate the missing values. Then add Gal to the hash table.
b) What happens when you try to add Cat and Ian to the table? Use open hashing with linear probing
to first add Cat and then Ian to the array.
c) What happens if we try to add Zoe (with a key of 302) to the table? How do we have to transform
the hash function to ensure it works for all names in U? (With the given key calculation.)
d) How could you alter the calculation of the key to avoid getting the same key for two different names?
(The given calculation gives the same key of 277 for Hal and Kai or 280 for Ian and Ina.) How would
you have to transform the hash function to deal with the new key generation.
Optional: If you would like to fill the whole table you can add these names U2 = {Ada,Cal,Ele,Gal,Ida,Kai ,
Lou,Max,P i a} ⊆ U to a new array using the key generation and hash function above.
Page 1 of 2
Exercise 6.3 – Cuckoo hashing (4 Points)
Given two hash functions h1 ,h2 : {A − F } → {1, . . . ,m}. The values for the first hash function are given by
the following array; e.g. h1 (A) = h1 (D) = 1 and h1 (C) = 4. The values for the second hash function are
indicated by the arrows; e.g. h2 (A) = 4 and h2 (D) = 7.
Apply the insert method of the Cuckoo-Hashing algorithm from class to the elements A,B,C,D,E,F (in this
order). Use an array of size m = 10. Log each step of insertion.
Use the universal class Hp,m with appropriate values for p and m to pick your hash functions from. Log each
step, even if you had to discard a hash function.
Page 2 of 2