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
How does Rabin Karp handle hash collisions?
When hash values match, Rabin Karp checks the actual characters of the substring and pattern to confirm a real match, avoiding false positives from collisions.
Click to reveal answer
intermediate
What is the rolling hash technique in Rabin Karp?
Rolling hash efficiently computes the hash of the next substring by removing the leading character and adding the trailing character, avoiding full recomputation.
Click to reveal answer
intermediate
Why is a prime number often used as the modulus in Rabin Karp hashing?
Using a prime modulus reduces the chance of hash collisions and helps distribute hash values more uniformly.
Click to reveal answer
intermediate
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 causing many character comparisons.
Click to reveal answer
What does Rabin Karp use to quickly compare the pattern with substrings of the text?
✗ Incorrect
Rabin Karp uses hash values to quickly compare the pattern with substrings, reducing direct comparisons.
What happens if two substrings have the same hash value in Rabin Karp?
✗ Incorrect
Hash collisions can occur, so Rabin Karp verifies by checking characters when hash values match.
What is the purpose of the rolling hash in Rabin Karp?
✗ Incorrect
Rolling hash updates the hash value efficiently by removing the old character and adding the new one.
Why is a prime number used as modulus in Rabin Karp hashing?
✗ Incorrect
Prime modulus helps distribute hash values evenly and reduces collisions.
What is the worst-case time complexity of Rabin Karp?
✗ Incorrect
Worst case is O(n*m) due to many hash collisions causing repeated character checks.
Explain how Rabin Karp uses hashing and rolling hash to find a pattern in a text.
Think about how hash values help avoid checking every character every time.
You got /4 concepts.
Describe the advantages and disadvantages of Rabin Karp compared to simple brute force string matching.
Consider speed and when it might slow down.
You got /4 concepts.
