🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: String Matching — KMP and Rabin-Karp: all 10 questions

Quiz: String Matching — KMP and Rabin-Karp · Question 5 of 10

Why is KMP search O(n + m)?

Why is KMP search O(n + m)?

  1. A.It skips half the text
  2. B.The text index only moves forward, and j can fall back at most as many times as it went up
  3. C.It sorts the text first
  4. D.It uses hashing
Answer & explanation

Correct answer: The text index only moves forward, and j can fall back at most as many times as it went up

j increases by at most 1 per text letter, so total fall-backs are at most n.

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 →