KMP-Algorithm finds all the occurences of a pattern in a given string. Naive pattern searching algorithm takes O(|P|*(|S|-|P|+1)) time whereas KMP Algorithm’s worst case time complexity is O(|S|) where S is the text string and P is the pattern we are looking for.
For example S = ABCDABCDAB and P = ABCDAB, then the algorithm should detect the pattern at indices 0 and 4.