/kmp

KMP string search algorithm implemented in Python

Primary LanguagePythonMIT LicenseMIT

KMP Knuth–Morris–Pratt string search algorithm implemented in Python

String algorithm for fun! Detailed information can be found on my blogger MuTuX.

Examples

if __name__ == "__main__":
    kmp('abcbabca','abcbabcabcbabcbabcbabcabcbabcbabca')

    kmp('abab','ababcabababc')

Results

========================================================
[-1, 0, 0, 0, 0, 1, 2, 3, 1]
0 7
15 22
26 33
[-1, 0, 0, 1, 2]
0 3
5 8
7 10

Finally

Have fun!