Computer scienceAlgorithms and Data StructuresAlgorithmsString algorithmsSubstring search algorithms

Rabin-Karp algorithm

Applying the Rabin-Karp algorithm

Report a typo

There are a pattern p=DDA p = \textrm{DDA} and a text t=DDABCD t = \textrm{DDABCD} . Apply the Rabin-Karp algorithm for the strings using the polynomial hash function with a=3a = 3 and m=11m = 11.

The output should contain tp+1|t|-|p| + 1 lines consisting of 3 numbers: the first is the hash value for the current substring of the text, the second is the number of symbol-by-symbol comparisons of the pattern with the current substring, and the third is 1 if the substrings are equal and 0 otherwise.

Keep it in mind that hashes are calculated starting from the right.

For instance, the output may look like this:

1 2 3
4 5 6
7 8 9
7 7 7
Enter a short text
___

Create a free account to access the full topic