Question
Suppose we want to find the first occurrence of a string P1 P2 Pk in a long input string A1 A2 AN . We can
Suppose we want to find the first occurrence of a string P1 P2 Pk in a long input string A1 A2 AN . We can solve this problem by hashing the pattern string, obtaining a hash value HP, and comparing this value with the hash value formed from A1A2 Ak, A2A3 Ak+1, A3A4 Ak+2, and so on until ANk+1ANk+2 AN. If we have a match of hash values, we compare the strings character by character to verify the match. We return the position (in A) if the strings actually do match, and we continue in the unlikely event that the match is false.
Write a program that implements this algorithm in c++
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started