Skip to content

Files

Latest commit

f966ef5 · May 21, 2018

History

History
This branch is 13 commits ahead of, 634 commits behind trekhleb/javascript-algorithms:master.

knuth-morris-pratt

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Apr 24, 2018
May 21, 2018
Apr 24, 2018

Knuth–Morris–Pratt Algorithm

The Knuth–Morris–Pratt string searching algorithm (or KMP algorithm) searches for occurrences of a "word" W within a main "text string" T by employing the observation that when a mismatch occurs, the word itself embodies sufficient information to determine where the next match could begin, thus bypassing re-examination of previously matched characters.

Complexity

  • Time: O(|W| + |T|) (much faster comparing to trivial O(|W| * |T|))
  • Space: O(|W|)

References