Unit 2 - Letter ManipilationPattern Searching
Unit 2 - Letter ManipilationPattern Searching
13
Rabin-Karp Algorithm
pattern is M characters long
hash_p=hash value of pattern
hash_t=hash value of first M letters in body of text
do
if (hash_p == hash_t)
brute force comparison of pattern and selected section of
text
hash_t= hash value of next section of text, one character over
while (end of text)
14
What is the hash
function used to
calculate values for
character sequences?
Hash Function
• Let b be the number of letters in the alphabet. The text subsequence t[i .. i+M-1] is
mapped to the number
Write a function search(char P[], char T[]) that prints all occurrences of
P[] present in T[] using Rabin Karp algorithm.