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 316 students.
Show answer & explanation
Correct answer: C
Hash function: f(key) = key mod 7
Insert keys one by one using linear probing:
37 mod 7 = 2 → place at index 2
38 mod 7 = 3 → place at index 3
72 mod 7 = 2 → collision at index 2 (occupied by 37), so check index 3 (occupied by 38), then index 4 → place at index 4
48 mod 7 = 6 → place at index 6
98 mod 7 = 0 → place at index 0
11 mod 7 = 4 → collision at index 4 (occupied by 72), so check index 5 → free → place at index 5
The location of key 11 is 5.
----------------------------------------
हैश फंक्शन: f(key) = key mod 7
कुंजियों को क्रम से डालते हैं:
37 mod 7 = 2 → इंडेक्स 2
38 mod 7 = 3 → इंडेक्स 3
72 mod 7 = 2 → टकराव → इंडेक्स 2 (37 द्वारा लिया गया), इंडेक्स 3 (38 द्वारा लिया गया), इंडेक्स 4 → इंडेक्स 4 पर रखें
48 mod 7 = 6 → इंडेक्स 6
98 mod 7 = 0 → इंडेक्स 0
11 mod 7 = 4 → टकराव → इंडेक्स 4 (72 द्वारा लिया गया), इंडेक्स 5 → खाली → इंडेक्स 5 पर रखें
अतः कुंजी 11 का स्थान 5 है।