Recall & Review
beginner
What is the main idea behind the Rabin Karp string matching algorithm?
It uses hashing to find a pattern in a text by comparing hash values of the pattern and substrings of the text, reducing the number of direct character comparisons.
Click to reveal answer
intermediate
Why does Rabin Karp use a rolling hash?
A rolling hash allows efficient computation of hash values for consecutive substrings by updating the previous hash instead of recalculating from scratch.
Click to reveal answer
intermediate
What happens if two substrings have the same hash value in Rabin Karp?
Since hash collisions can occur, the algorithm checks the actual characters of the substrings to confirm if they really match.
Click to reveal answer
advanced
What is the average and worst-case time complexity of Rabin Karp?
Average case is O(n + m) where n is text length and m is pattern length. Worst case is O(n*m) due to hash collisions requiring full substring checks.
Click to reveal answer
intermediate
Explain the role of the modulus in Rabin Karp hashing.
The modulus keeps hash values within a fixed range to avoid overflow and helps in distributing hash values uniformly to reduce collisions.
Click to reveal answer
What does Rabin Karp primarily use to speed up pattern matching?
✗ Incorrect
Rabin Karp uses hashing to quickly compare the pattern with substrings of the text.
What is a rolling hash in Rabin Karp?
✗ Incorrect
Rolling hash updates the hash value by removing the old character and adding the new one efficiently.
If two substrings have the same hash, what does Rabin Karp do next?
✗ Incorrect
Because of possible collisions, Rabin Karp verifies the actual substring characters.
What is the worst-case time complexity of Rabin Karp?
✗ Incorrect
Worst case happens when many hash collisions cause repeated substring checks, leading to O(n*m).
Why is modulus used in Rabin Karp hashing?
✗ Incorrect
Modulus keeps hash values manageable and helps distribute them evenly.
Describe how the Rabin Karp algorithm finds a pattern in a text using hashing.
Think about how hash values help avoid checking every character every time.
You got /4 concepts.
Explain why Rabin Karp might sometimes perform slower than expected and how it handles that situation.
Consider what happens when different substrings have the same hash.
You got /3 concepts.