Mental Model
KMP finds a pattern in text by skipping unnecessary checks using a precomputed table.
Analogy: Imagine searching a word in a book but remembering how much you matched before so you don't start over from the beginning each time.
Text: A B C D A B C D A B C D
Pattern: A B C D A B
↑
Prefix Table: [0 0 0 0 1 2]