Consider a hash table with 9 slots. The hash function is ℎ(k) = k mod 9. The collisions are resolved by chaining. The following 9 keys are inserted in the order: 5, 28, 19, 15, 20, 33, 12, 17, 10. The maximum, minimum, and average chain lengths in the hash table, respectively, are
(A) 3, 0, and 1
(B) 3, 3, and 3
(C) 4, 0, and 1
(D) 3, 0, and 2
Answer: (A)
Explanation: Following are values of hash function for all keys
5 --> 5
28 --> 1
19 --> 1 [Chained with 28]
15 --> 6
20 --> 2
33 --> 6 [Chained with 15]
12 --> 3
17 --> 8
10 --> 1 [Chained with 28 and 19]
The maximum chain length is 3. The keys 28, 19 and 10 go to same slot 1, and form a chain of length 3.
The minimum chain length 0, there are empty slots (0, 4 and 7).
Average chain length is (0 + 3 + 1 + 1 + 0 + 1 + 2 + 0 + 1)/9 = 1
Quiz of this Question
Level Up Your GATE Prep!
Embark on a transformative journey towards GATE success by choosing
Data Science & AI as your second paper choice with our specialized course. If you find yourself lost in the vast landscape of the GATE syllabus, our program is the compass you need.
Last Updated :
28 Jun, 2021
Like Article
Save Article