Mental Model
KMP finds a pattern in a text by skipping unnecessary checks using a precomputed table.
Analogy: Imagine searching for a word in a book. Instead of going back to the start after a mismatch, you remember how much matched and jump ahead to avoid rechecking letters.
Text: A B C D A B C D A B C D
Pattern: A B C D
↑