Question

Perform Rabin-Karp search on text 011010011001110 with pattern 111 and q = 6 and explain your...

Perform Rabin-Karp search on text 011010011001110 with pattern 111 and q = 6 and explain your results.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here pattern length (m) = 3

Text length (n) = 6

q = 6 which is used as base of powers in the hash function.

Rabin-Karp works on hash function let's define the hash function for this->

60 * no. present at index 0 of the sub-string of the given text + 61*no. present at index 1 of the sub-string of the given text + 62 * no. present at index 2 of the sub-string of the given text.

The value we got using the above hash function is called hash value.

The above hash function takes power up-to 2 because the length of the pattern to match is 3 i.e 0, 1, 2 are 3 powers. The hash function taken for each sub- string from the start rolled towards the end of the given text also known as rolling hash function.

First sub-string from the given text of length 3 is taken because pattern length is also 3 and we take the next sub-string by sliding on by 1 value that is first is 011, next will 110 and so on.

011 010 011 001 110

Above I show the distribution of given text into sub-string of length 3

Hash value for the pattern is :

60 * 1 + 61 * 1 + 62 * 1

1 + 6 + 36

43

Now, let's find out hash function for 1st sub-string that is 011->

60 * 0 + 61 * 1 + 62 * 1

0 + 6 + 36

42 which is not equal to pattern hash value that is 43.

Hence, pattern not matched here. Let's roll over to next sub-string which is 010

Hash value of 010 is:

60 * 0 + 61 * 1 + 62 * 0 = 6 not equal to 43.

Hence, pattern not matched. Next sub-string: 011

hash value of 011 is:

60 * 0 + 61 * 1 + 62 * 1 = 42 not equal to 43.

Next sub-string is- 001

hash value for 001 is:

60 * 0 + 61 * 0 + 62 * 1 = 36 not equal to 43.

Next sub-string is : 110

hash value is :

60 * 1 + 61 * 1 + 62 * 0 = 12 not equal 43.

On traversing the entire text the pattern is not found. This is the final result of the rabin-karp.

Add a comment
Know the answer?
Add Answer to:
Perform Rabin-Karp search on text 011010011001110 with pattern 111 and q = 6 and explain your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT