Computer scienceAlgorithms and Data StructuresAlgorithmsString algorithmsSubstring search algorithms

Rabin-Karp algorithm

Applying the algorithm

Report a typo

There is a pattern p=ACC p = \textrm{ACC} and a text t=AACCDB t = \textrm{AACCDB} . Apply the Rabin-Karp algorithm for the strings using the polynomial hash functions 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, the third is 1 if the substrings are equal and 0 otherwise.

Keep it in mind that hash values 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