🎉 October Learning Month — learn a new software term every day!
An interactive flashcard trainer for software engineering terms.

KMP

In plain terms

A linear-time string search avoiding redundant comparisons.

Going deeper

The Knuth-Morris-Pratt algorithm precomputes a table of pattern prefixes so that after a mismatch it never re-checks already-matched characters. It guarantees linear time.

Under the hood

O(n+m) via a failure/prefix function that tells how far to shift on mismatch without backtracking the text.

Examples

Text search, DNA matching, pattern detection, grep implementations.

Think of it like...

Like a reader who, on a mismatch, knows exactly how far back the pattern could still align, without rereading.

Feedback & Bug Report