ProgrammingHard

Keys 8, 16, 24 and 32 are hashed with h(k) = k % 8 and then with h(k) = k % 7. Which statement is correct?

  1. A. They all collide at slot 0 under both hashes
  2. B. They collide only under mod 7
  3. C. They land in distinct slots under both hashes
  4. D. They all collide at slot 0 with mod 8 but land in distinct slots 1 to 4 with mod 7

Correct answer: D. They all collide at slot 0 with mod 8 but land in distinct slots 1 to 4 with mod 7

Multiples of 8 all become 0 under mod 8, which is why a power-of-two table size needs a good mixing function. Mod 7 separates them into slots 1, 2, 3 and 4.

More C Programming questions

Exams that ask this topic