Knuth–Morris–Pratt algorithm

E94984

The Knuth–Morris–Pratt algorithm is a classic linear-time string-searching algorithm that efficiently finds occurrences of a pattern within a text by precomputing a prefix function to avoid redundant comparisons.

AI illustration

How this image was made

AI-generated illustration of Knuth–Morris–Pratt algorithm

This AI-generated illustration was produced by black-forest-labs/FLUX.2-dev (1024x1024) from a prompt written by openai/gpt-oss-120b from the entity's label + description.

Prompt

Generate an image of the Knuth–Morris–Pratt algorithm (The Knuth–Morris–Pratt algorithm is a classic linear-time string-searching algorithm that efficiently finds occurrences of a pattern within a text by precomputing a prefix function to avoid redundant comparisons.)

All labels observed (4)

How this entity was disambiguated

Statements (50)

Predicate Object
instanceOf deterministic algorithm ⓘ
linear-time algorithm ⓘ
pattern-matching algorithm ⓘ
string-search algorithm ⓘ
application pattern matching in compilers ⓘ
search in DNA or protein sequences ⓘ
search in network intrusion detection systems ⓘ
text editors search functionality ⓘ
authorsOfOriginalPaper Donald E. Knuth ⓘ
James H. Morris Jr. ⓘ
linked to: James H. Morris

Vaughan R. Pratt ⓘ
linked to: Vaughan Pratt
avoids backtracking in the text ⓘ
re-examining characters in the text ⓘ
category exact string matching algorithms ⓘ
comparedWith Boyer–Moore algorithm ⓘ
Rabin–Karp algorithm ⓘ
naive string-search algorithm ⓘ
describedIn "Fast Pattern Matching in Strings" ⓘ
field algorithms ⓘ
computer science ⓘ
stringology ⓘ
hasPhase preprocessing phase ⓘ
search phase ⓘ
input pattern string ⓘ
text string ⓘ
introducedIn 1977 ⓘ
keyIdea avoid redundant comparisons by reusing previous match information ⓘ
precompute longest proper prefix which is also suffix for each pattern position ⓘ
namedAfter Donald Knuth ⓘ
linked to: Donald E. Knuth

James H. Morris ⓘ
Vaughan Pratt ⓘ
output starting indices of pattern occurrences in text ⓘ
preprocessingPhaseComplexity O(m) ⓘ
property guaranteed worst-case linear time ⓘ
runs in time linear in the length of the text plus pattern ⓘ
stable performance independent of alphabet size ⓘ
purpose find occurrences of a pattern in a text ⓘ
searchPhaseComplexity O(n) ⓘ
spaceComplexity O(m) ⓘ
taughtIn data structures and algorithms curricula ⓘ
undergraduate algorithms courses ⓘ
timeComplexity O(n + m) ⓘ
timeComplexityBestCase O(n) ⓘ
timeComplexityWorstCase O(n + m) ⓘ
typicalRepresentation pseudocode in algorithm textbooks ⓘ
usesConcept border of a string ⓘ
failure function ⓘ
prefix function ⓘ
proper prefix ⓘ
proper suffix ⓘ

How these facts were elicited

Referenced by (10)

Full triples — surface form annotated when it differs from this entity's canonical label.

Donald E. Knuth → knownFor → Knuth–Morris–Pratt algorithm ⓘ
Knuth–Morris–Pratt algorithm → describedIn → "Fast Pattern Matching in Strings" ⓘ
linked to: Knuth–Morris–Pratt algorithm
Boyer–Moore string-search algorithm → comparedWith → Knuth–Morris–Pratt algorithm ⓘ
Vaughan Pratt → knownFor → Knuth–Morris–Pratt string-searching algorithm ⓘ
linked to: Knuth–Morris–Pratt algorithm
Vaughan Pratt → coDeveloperOf → Knuth–Morris–Pratt string-searching algorithm ⓘ
linked to: Knuth–Morris–Pratt algorithm
Rabin–Karp algorithm → comparesWith → Knuth–Morris–Pratt algorithm ⓘ
James H. Morris → knownFor → Knuth–Morris–Pratt string-searching algorithm ⓘ
linked to: Knuth–Morris–Pratt algorithm
James H. Morris → coDeveloperOf → Knuth–Morris–Pratt string-searching algorithm ⓘ
linked to: Knuth–Morris–Pratt algorithm
Aho–Corasick algorithm → relatedTo → Knuth–Morris–Pratt algorithm ⓘ
Military Police of Lithuania → hasAbbreviation → KMP ⓘ
linked to: Knuth–Morris–Pratt algorithm