Prefix-suffix sequence recognizer

ID: prefix-suffix-sequence-recognizer

For a fixed word , store the length of the longest suffix of the received stream that is also a prefix of . On a new input symbol, append it to the represented prefix and select the longest resulting suffix that is a prefix of . The complete-word state signals recognition. Its outgoing transitions retain proper suffix matches, allowing overlapping occurrences rather than automatically restarting from the empty prefix. This is the finite-state form of the prefix information used by the Knuth-Morris-Pratt algorithm.
For example, recognizing needs suffix-prefix states of lengths zero through four. After a complete match followed by one, the last two symbols are , so the next state retains length two. This permits the second match in without clearing the useful suffix.

New to topics? Read the docs here!