Knuth-Morris-Pratt

The Knuth-Morris-Pratt (KMP) algorithm is an algorithm for finding a pattern in a string.

The algorithm was conceived in 1974 by Donald Knuth and Vaughan Pratt, and independently by James H. Morris. The three published it jointly in 1977.

Time Complexity
The algorithm's time complexity is $$O(n + m)$$ if $$n$$ and $$m$$ are the lengths of the pattern and the text. This is better than the trivial $$O(nm)$$ solution.