Professional Documents
Culture Documents
ALgorthoms Midterm 2021
ALgorthoms Midterm 2021
Q1 Assume you have hash table T with size = 10 Add these values
(0,30,1,55,16,28,13,9 ,26) in it using the following methods,
[10 point 2.5 for each one]
1- Linear probing using hash function h(key) = key % 10
index Value
0 0
1 30
2 1
3 13
4
5 55
6 16
7 26
8 28
9 9
3- Double hashing Assume the main hash function h1(key) = key % 10 And
the second hash function h2(key) = 5 – (key % 5).
hi(key)=(h1(key)+i*(h2(key)) mod 10,
0,30,1,55,16,28,13,9 ,26)
55 cannot inserted
Index Value
0 0
1 1
2
3 13
4 26
5 30
6 16
7
8 28
9 9
4- Chaining.
0,30,1,55,16,28,13,9 ,26)
Index 0 30
0 1
1
2
3 13
4
5 55
6 16 26
7
8 28
9 9
Q2 How would you optimally calculate p^k, where k is a non-negative integer?
What is the complexity of the solution?[5 points]