← Quiz: String Matching — KMP and Rabin-Karp: all 10 questions
Quiz: String Matching — KMP and Rabin-Karp · Question 9 of 10
When is Rabin-Karp especially useful compared with KMP?
When is Rabin-Karp especially useful compared with KMP?
- A.When the pattern is a single letter
- B.When searching for many patterns of the same length at once
- C.When you need a guaranteed worst-case time
- D.When the text is shorter than the pattern
Answer & explanation
Correct answer: When searching for many patterns of the same length at once
Put all pattern hashes in a set and check each window's hash against it.
Can you get the rest right without peeking?
Take the timed Quiz: String Matching — KMP and Rabin-Karp quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →