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 vmb in stvmbocti. The fingerprints agree only at places 1 and 3. How many letter comparisons does it make?

the answer, and why

the answer is A

Place 1, stv: s is not v, 1. Place 3, vmb: v, m and b match, 3. No other place compares. That is 4.

if you chose another

  • That compares all 3 letters at both places, but place 1 stops at its first letter.
  • That counts only the match, not the chance agreement at place 1.
  • That compares all 3 letters at all 7 places, the most any search of 9 letters and 3 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 B

Letters are compared only where the fingerprints agree, by chance or because the pattern is there. aaaaaadaad, ddaaa compares 1 letter, the fewest of the four.

if you chose another

  • That compares 5 letters, more than 1.
  • That compares 3 letters, more than 1.
  • That compares 5 letters, more than 1.

new numbersthe test page's numbers