Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 571 Bytes

README.md

File metadata and controls

29 lines (22 loc) · 571 Bytes

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!