GATE Computer ScienceHardGATE CS (PYQ pattern)

Rabin–Karp searches for P = 26 in T = 3141592653589793 using base 10 and modulus 11 on 2-digit windows. How many spurious hits (hash equal but the window is different from P) occur?

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

Correct answer: A. 3

26 mod 11 = 4. Windows with value ≡ 4 (mod 11) are 15, 59, 92 and 26; only the last equals P, so 3 are spurious hits. Each spurious hit costs an extra O(m) character comparison.

More Algorithms questions

Exams that ask this topic