A hash function h defined h(key)=key mod 7, with linear probing, is used to…
2018
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
Attempted by 313 students.
Show answer & explanation
Correct answer: C
Insert keys using h(key) = key mod 7 with linear probing into indices 0..6.
44 -> 44 mod 7 = 2, place at index 2.
45 -> 45 mod 7 = 3, place at index 3.
79 -> 79 mod 7 = 2, index 2 is occupied, probe to index 3 (occupied), probe to index 4, place at index 4.
55 -> 55 mod 7 = 6, place at index 6.
91 -> 91 mod 7 = 0, place at index 0.
18 -> 18 mod 7 = 4, index 4 is occupied (by 79), probe to index 5 which is free, place 18 at index 5.
Final location of key 18: index 5.
A video solution is available for this question — log in and enroll to watch it.