Knuth-Morris-Pratt
The Knuth-Morris-Pratt (KMP) algorithm is an efficient method for searching a substring within a larger string. It improves upon the naive search approach by avoiding unnecessary comparisons. The algorithm preprocesses the pattern to create a partial match table, which helps in determining how far to shift the pattern when a mismatch occurs.
When a mismatch happens, the KMP algorithm uses the information from the partial match table to skip over sections of the text that have already been matched. This results in a linear time complexity of O(n + m), where n is the length of the text and m is the length of the pattern, making it suitable for large-scale string searching tasks.