GATE Computer ScienceModerateGATE CS (PYQ pattern)

Keys 10, 20, 30, …, 100 are inserted in this order into an empty hash table of size 10 with h(k) = k mod 10 and quadratic probing (h(k) + i²) mod 10 for i = 0, 1, …, 9. A key whose 10 probes all hit occupied slots is rejected. How many of the 10 keys are stored?

  1. A. 10
  2. B. 6
  3. C. 5
  4. D. 7

Correct answer: B. 6

All keys hash to 0, and i² mod 10 for i = 0…9 takes only the values 0, 1, 4, 9, 6, 5 — six distinct slots. So 10, 20, 30, 40, 50, 60 fill slots 0, 1, 4, 9, 6, 5, and from 70 on every key is rejected even though slots 2, 3, 7, 8 are free.

More Algorithms questions

Exams that ask this topic