string - Is it possible to use the KMP algorithm to find a longest substring? -


suppose have pattern p , text t, , want find largest prefix of p matches substring of t. possible modify kmp algorithm such operation? (if remember correctly, kmp algorithm partial matches, interested in longest possible match).

as kmp scanning text, state of kmp shows length of longest prefix of pattern matches text current point, record maximum length seen , point in pattern @ seen, , use find longest matching prefix of p.

another way of doing put prefixes of p aho-corasick. run-time behaviour similar, although consume little more store. allow use existing library - if had 1 aho-corasick, instead of modifying kmp implementation.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -