The KMP algorithm is a solution to the string search problem wherein we are required to find if a given pattern string occurs in another main string. It is one of the advanced string matching algorithms that was conceived by Donald Knuth, James H. Morris and Vaughan Pratt, hence the name “KMP algorithm”.

The algorithm keeps a track of the comparison of characters between main text and pattern, thereby ensuring that comparisons that have already been done are not repeated, i.e. backtracking of the main string never occurs. …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store