GATE / CS ARCHIVE

GATE CSE 2009 / QUESTION 36

Linear-probing hash insertion

Data Structures · Hashing · Full GATE CSE 2009 paper

GATE 2009, Q36 2 marks · MCQ
Report issue

Hashing

Question 36, GATE 2009: Insert 12, 18, 13, 2, 3, 23, 5, 15 in an empty 10-slot table using h(k)=k mod 10 and linear probing. Candidate A stores 2:2, 3:23, 5:15, 8:18; B stores 2:12, 3:13, 5:5, 8:18; C stores slots 2–9 as 12, 13, 2, 3, 23, 5, 18, 15; D chains 2:[12, 2], 3:[13, 3, 23], 5:[5, 15], 8:[18]. Other slots empty. Which is correct?
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step through it (10 steps)

Insertions place 12 at 2, 18 at 8, 13 at 3, 2 at 4, 3 at 5, 23 at 6, 5 at 7 and 15 at 9 after probing past occupied slots 5 through 8. The final slots 2–9 are 12, 13, 2, 3, 23, 5, 18, 15, exactly option C.

Probe consecutive slots until empty. First 12→2 and 18→8; 13→3. Key 2 collides at 2 and 3, so goes 4. Key 3 goes 5; 23 goes 6; 5 goes 7. Finally 15 probes 5, 6, 7, 8 before reaching 9. This yields candidate C. D instead uses chaining, which is explicitly not the requested collision strategy; A/B discard keys rather than preserving them in later empty slots.

Original paper, page 8