KMP precomputes a prefix function (LPS) so when a mismatch happens, it shifts the pattern without re-checking characters. This makes search O(n+m) instead of O(n·m).
KMP avoids repeated comparisons by reusing information about the pattern.
Core idea:
That guarantees the text index never moves backwards, so total complexity is O(n+m).