← 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?
- A.Moves the text pointer back by j positions
- B.Sets j to 0 and moves on
- C.Stops the search
- 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 →