Data Structures & AlgorithmsModerateInfosys · Wipro pattern

Double hashing in a table of size 11 uses h1(k) = k mod 11 and h2(k) = 7 − (k mod 7); probe i goes to (h1 + i·h2) mod 11. Keys 14, 25, 36 are inserted in that order. In which slot does 36 end up?

  1. A. 4
  2. B. 9
  3. C. 5
  4. D. 1

Correct answer: B. 9

14 → 14 mod 11 = 3. 25 → 3 is taken; h2(25) = 7 − 4 = 3, so it goes to 6. 36 → 3 taken; h2(36) = 7 − 1 = 6: (3 + 6) mod 11 = 9, which is free. Linear probing would have put 36 at slot 4 and 25 at 4 as well; '5' uses the h2 of 25 for 36.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic