🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: String Matching — KMP and Rabin-Karp: questions with answers

10 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. What is the worst-case time of naive string matching for text length n and pattern length m?
  2. Q2. What does lps[i] store in KMP?
  3. Q3. What does this print? (code)
  4. Q4. When KMP finds a mismatch after j letters matched (j 0), what does it do?
  5. Q5. Why is KMP search O(n + m)?
  6. Q6. What does this print? (code)
  7. Q7. In Rabin-Karp, why compare the letters when two hashes are equal?
  8. Q8. What does this print? (code)
  9. Q9. When is Rabin-Karp especially useful compared with KMP?
  10. Q10. A string has length 9 and lps[8] = 6. What does that tell you?