GATE | GATE CS 1997 | Question 56

A hash function h defined h(key)=key mod 7, with linear probing, is used to insert the keys 44, 45, 79, 55, 91, 18, 63 into a table indexed from 0 to 6. What will be the location of key 18?
(A) 3
(B) 4
(C) 5
(D) 6


Answer: (C)

Explanation: keys 44, 45, 79, 55, 91, 18, 63
h(key)= key mod 7
h(44) = 44mod7 = 2
h(45) = 45mod7 = 3
h(79) = 79mod7 = 2
but 2 is already filled by 44, linear probing is applied but 3 is also filled by 45.
So, 79 will occupy 4.
h(55) = 55mod7 = 6
h(91) = 91mod7 = 0
h(18) = 18mod7 = 4 but 4 is occupied by 79 so, it will occupy 5.
h(63) = 63mod7 = 0. 0 is also occupied so, it will occupy 1.
So, option (C) is correct.

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.