A hash function defined as f(key)=key mod 7 with linear probing is used to…
2018
A hash function defined as f(key)=key mod 7 with linear probing is used to insert the keys 37, 38, 72, 48, 98, 11, 56 into a table indexed from 0 to 6. What will be the location of key 11?
- A.
3
- B.
4
- C.
5
- D.
6
Attempted by 381 students.
Show answer & explanation
Correct answer: C
Key steps using f(key) = key mod 7 with linear probing:
Insert 37: 37 mod 7 = 2 → place at index 2
Insert 38: 38 mod 7 = 3 → place at index 3
Insert 72: 72 mod 7 = 2 → index 2 occupied → probe to index 3 (occupied) → probe to index 4 (free) → place at index 4
Insert 48: 48 mod 7 = 6 → place at index 6
Insert 98: 98 mod 7 = 0 → place at index 0
Insert 11: 11 mod 7 = 4 → index 4 is occupied (by 72) → probe to index 5 (free) → place at index 5
Insert 56 (remaining key): 56 mod 7 = 0 → index 0 is occupied (by 98) → probe to index 1 (free) → place at index 1
Final table (index : key):
Index 0 : 98
Index 1 : 56
Index 2 : 37
Index 3 : 38
Index 4 : 72
Index 5 : 11
Index 6 : 48
Answer: Location of key 11 = 5