String Matching¶
Quick Start Guide¶
String Matching Algorithms¶
Author : Robin Singh
Programs List :
1 . Knuth Morris Pratt String Matching Algorithm 2 . Naive Method 3 . Rabin Karp String Matching Algorithm
Knuth Morris Pratt¶
- Example :
# import required algorithm >>> from package.pygostructures.algorithms.string_matching import KnuthMorrisPratt # string to be searched >>> string1 = "csk" # main string from which string 1 has to be searched >>> string2 = "jadhgdajdkcsklsdhajhd" >>> a = KnuthMorrisPratt(string1,string2) >>> a.knuth_morris_pratt() Pattern Found At Index :10
Naive Method¶
- Example :
# import required algorithm >>> from pythorn.algorithms.string_matching import NaiveMethod # string to be searched >>> string1 = "in" # main string from which string 1 has to be searched >>> string2 = "djhdjhdinqwert" >>> a = NaiveMethod(string1,string2) >>> a.naive_method() Pattern Found At Index :7
Rabin Karp¶
- Example :
# import required algorithm >>> from pythorn.algorithms.string_matching import RabinKarp # string to be searched >>> string1 = "in" # main string from which string 1 has to be searched >>> string2 = "djhdjhdinqwert" >>> a = RabinKarp(string1,string2) >>> a.rabin_karp() Pattern Found At Index :7