[prev] 40 [next]

Preprocessing Strings

Preprocessing the pattern speeds up pattern matching queries
  • After preprocessing P, KMP algorithm performs pattern matching in time proportional to the text length
If the text is large, immutable and searched for often (e.g., works by Shakespeare)
  • we can preprocess the text instead of the pattern