🎙 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 4 of 10

When KMP finds a mismatch after j letters matched (j 0), what does it do?

When KMP finds a mismatch after j letters matched (j > 0), what does it do?

  1. A.Moves the text pointer back by j positions
  2. B.Sets j to 0 and moves on
  3. C.Stops the search
  4. D.Sets j = lps[j − 1] and compares the same text letter again
Answer & explanation

Correct answer: Sets j = lps[j − 1] and compares the same text letter again

The text pointer never goes back; only j falls back to a shorter prefix that can still match.

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 →