Machine-translated by Google. Questions are authored in English.
Top

Discussion

Working modulo q = 11, how many spurious hits does the Rabin Karp matcher encounter in the text T = 459263781 when working for the pattern β = 37 :

  • A.2
  • B.3
  • C.4
  • D.5

Answer: C

The matcher encounters 4 spurious hits.

The pattern's hash is 37 mod 11 = 4. Rabin-Karp compares this with the hash of every two-digit window of the text 459263781:

4559922663377881
14448414

Five windows hash to 4: 59, 92, 26, 37 and 81. Only 37 is a real match. The other four, 59, 92, 26 and 81, are spurious hits: their hash agrees with the pattern's but the digits do not.

Counting the true match as well gives 5, which is the trap in option D.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.