GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A hash table has 7 slots (0 to 6) and uses linear probing with h(k) = k mod 7. The six keys 8, 15, 3, 10, 5, 12 are inserted in some order. The final table, slots 0 to 6, is [None, 8, 15, 3, 10, 5, 12]. For how many of the 720 insertion orders is the final table exactly this?

  1. A. 180
  2. B. 90
  3. C. 96
  4. D. 45

Correct answer: B. 90

Brute force over all 720 orders gives 90: keys 8 and 15 (home slot 1) and 3, 10 (home slot 3), 5, 12 (home slot 5) compete, and only orders that respect the displacement constraints give this table.

More Programming and Data Structures (GATE) questions

Exams that ask this topic