← Quiz: String Matching — KMP and Rabin-Karp: all 10 questions
Quiz: String Matching — KMP and Rabin-Karp · Question 1 of 10
What is the worst-case time of naive string matching for text length n and pattern length m?
What is the worst-case time of naive string matching for text length n and pattern length m?
- A.O(n + m)
- B.O(n log m)
- C.O(n · m)
- D.O(m²)
Answer & explanation
Correct answer: O(n · m)
At each of about n starting positions it may compare up to m letters, as in searching "AAAB" in a long run of A's.
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 →