Skip to content

Rabin-Karp

words

Level 2 of 3

Also called Karp-Rabin algorithm and Rolling hash search.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from rabin-karp's own run on the numbers shown.

choose one

question 1

Rabin-Karp looks for qvqn in ketqvqns. The fingerprints agree only at places 2 and 4. How many letter comparisons does it make?

the answer, and why

the answer is D

Place 2, etqv: e is not q, 1. Place 4, qvqn: q, v, q and n match, 4. No other place compares. That is 5.

if you chose another

  • That compares all 4 letters at both places, but place 2 stops at its first letter.
  • That counts only the match, not the chance agreement at place 2.
  • That compares all 4 letters at all 5 places, the most any search of 8 letters and 4 could make.

new numbersthe test page's numbers

question 2

Each text has ten letters and each pattern five. Which makes Rabin-Karp compare the fewest letters?

the answer, and why

the answer is C

Letters are compared only where the fingerprints agree, by chance or because the pattern is there. cbcbbcbccb, bbcbb compares 0 letters, the fewest of the four.

if you chose another

  • That compares 6 letters, more than 0.
  • That compares 1 letter, more than 0.
  • That compares 1 letter, more than 0.

new numbersthe test page's numbers