Data Structures & AlgorithmsModerateTCS NQT · strings

Problem: Which concept is used by the Rabin-Karp algorithm to compare substrings in constant time?

  1. A. A suffix tree
  2. B. Dynamic programming over prefixes only
  3. C. Bitmask enumeration
  4. D. Rolling polynomial hashing

Correct answer: D. Rolling polynomial hashing

Rolling hashes update in constant time per shift, so each substring hash is compared in O(1).

More Coding Interview Problems questions

Exams that ask this topic