GATE / CS ARCHIVE

GATE CSE 2010 / QUESTION 52

Linear-probing insertion sequence

Data Structures · Hashing · Full GATE CSE 2010 paper

GATE 2010, Q52 2 marks · MCQ
Report issue

Hashing

Question 52, GATE 2010: A hash table has length ten, hash function h(k)=k mod 10, open addressing and linear probing. After six insertions into the initially empty table, slots 2,3,4,5,6,7 contain 42,23,34,52,46,33 respectively; slots 0,1,8,9 are empty. Which sequence could have produced this table?
Options: (A) 46,42,34,52,23,33; (B) 34,42,23,52,33,46; (C) 46,34,42,23,52,33; (D) 42,46,33,23,34,52.
Question 52, GATE 2010: A hash table has length ten, hash function h(k)=k mod 10, open addressing and linear probing. After six insertions into the initially empty table, slots 2,3,4,5,6,7 contain 42,23,34,52,46,33 respectively; slots 0,1,8,9 are empty. Which sequence could have produced this table?
Options: (A) 46,42,34,52,23,33; (B) 34,42,23,52,33,46; (C) 46,34,42,23,52,33; (D) 42,46,33,23,34,52.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Simulate option C: 46 hashes to slot 6, 34 to 4, 42 to 2, and 23 to 3. Then 52 starts at 2 and probes occupied slots 2,3,4, stopping at 5. Finally 33 starts at 3 and probes occupied slots 3,4,5,6, stopping at 7. This exactly reproduces the figure. In A, 52 is inserted before 23 and takes slot 3; in B, 33 is inserted before 46 and takes slot 6; in D, 33 takes slot 3 before 23. Those disagree with the shown table, leaving C.

Linear probing tests h(k),h(k)+1,… modulo ten until an empty slot is reached. This means final position depends on insertion order, not only on the hash value. In the valid order, the four home-slot keys 42,23,34,46 establish the required occupied run before the displaced keys arrive. Neither 52 nor 33 wraps around the table in this instance.

Original paper, page 13