KMP
KMP, or Knuth–Morris–Pratt algorithm, is a string-search algorithm that finds occurrences of a pattern P within a text T in O(n + m) time, where n is the length of T and m is the length of P. It achieves this efficiency by using information gathered during a preprocessing stage of the pattern to avoid unnecessary comparisons.
The preprocessing step computes the longest proper prefix that is also a suffix (the LPS array) for
During the search, the algorithm compares P and T from left to right. When characters match, both
KMP is widely used for exact substring search in applications such as text processing and bioinformatics. It