Knuth-Morris-Pratt
On a mismatch, drop j to pi[j - 1] so the pattern slides without re-reading any text character.
Cost
- Best
- O(n + m)
- Average
- O(n + m)
- Worst
- O(n + m)
- Space
- O(m)
Before this
Related
Leads to
Topics that need this one first.
Taught by the same lesson
String Matching covers these too, in the same run.