Data Structures & AlgorithmsVery hardICPC regional · GATE CS

A polynomial rolling hash with a fixed modulus M and random base B is used to compare two different strings of length L. Which statement is correct?

  1. A. Two different strings collide with probability at most about L/M over a random base, so a large prime M makes collisions rare
  2. B. Two different strings always have different hashes because the base is random
  3. C. Collisions only happen when the strings have different lengths, so equal-length strings never collide
  4. D. Using a larger base B always increases the number of collisions because hashes grow faster

Correct answer: A. Two different strings collide with probability at most about L/M over a random base, so a large prime M makes collisions rare

A nonzero polynomial of degree at most L has at most L roots mod M, so a random base collides with probability at most L/M. Equal-length strings can collide, and a larger base does not by itself create collisions.

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

Exams that ask this topic