An efficient string searching algorithm that searches for occurrences of a pattern string within a text string.
The Knuth-Morris-Pratt (KMP) algorithm is a string searching algorithm that searches for occurrences of a "pattern" within a main "text" string. It uses the observation that when a mismatch occurs, the pattern itself contains enough information to determine where the next match could begin, thus bypassing re-examination of previously matched characters.