Definition: A string matching algorithm that turns the search string into a finite state machine, then runs the machine with the string to be searched as the input string. Execution time is O(m+n), where m is the length of the search string, and n is the length of the string to be searched.
Also known as KMP.
Series of pages explaining how Knuth-Morris-Pratt works.
Donald E. Knuth, James H. Morris, and Vaughan R. Pratt, Fast Pattern Matching in Strings, SIAM Journal on Computing, 6(2):323-350, 1977.
If you have suggestions, corrections, or comments, please get in touch with Paul Black.
Entry modified 14 December 2020.
HTML page formatted Mon Dec 14 10:59:03 2020.
Cite this as:
Sterling Bates, "Knuth-Morris-Pratt algorithm", in Dictionary of Algorithms and Data Structures [online], Paul E. Black, ed. 14 December 2020. (accessed TODAY) Available from: https://www.nist.gov/dads/HTML/knuthMorrisPratt.html