KMP

Back to Pattern Matching

Knuth-Morris-Pratt algorithm. Preprocesses the pattern to build a failure function that allows the search to skip characters when a mismatch occurs, avoiding redundant comparisons. O(n + m) time where n is text length and m is pattern length.

algorithms string-algorithms kmp pattern-matching