AI engineering glossary · Data structures algorithms
What is KMP (Knuth-Morris-Pratt algorithm)?
Knuth-Morris-Pratt algorithm (also called KMP): A string matching algorithm that precomputes, for the pattern, how far to fall back after a mismatch so that no text character is examined twice. It searches in O(n + m) time.
Knuth-Morris-Pratt algorithm: an example
Searching 'ABABC' in a text, after a mismatch it jumps using the pattern's prefix table rather than restarting from the next text character.
Related terms
More Data structures algorithms terms
- Kruskal's algorithm
- Linear search
- Linked list
- Load factor
- Longest common subsequence
- Longest increasing subsequence
- LRU cache
- Master theorem
Where you learn it
Knuth-Morris-Pratt algorithm is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.