regex - Algorithm for 2 Pattern String Matching -
I need an algorithm code to match two pattern prefix / suffix for the longest time, whose time complexity is O (n + M1 + m2), where n is the length of string and m1, m2 is the length of pattern 1 and pattern 2 respectively. Example: If the string is "obtoto" and the pattern is 1 "bana" and Patton 2 is "SIESTA", then the answer is "nickname" of the string, in which the prefix of Bana and the suffix Ti of SIESTA are included. Results from Google: "Rabin-Carp String Search Algorithm", "Noth-Morris-Prat Algorithm" and "Bauer-Moore String Search Algorithm".
I am able to understand all of the above 3 algorithms, but the problem is that they are unable to expand to all the "single pattern prefix / suffix matching" to match them in two pattern prefix / suffix.
A sample algorithm or a link to search would be very useful for me in developing the program.
Knuth - Morris - Protea can be modified directly for yield, each in the greenstack string For the position, the length of the long prefix of the needle string with the match ending at that place. Use KMP to calculate this information for the straight and reverse (pat 2) of Pat 1 in the string, then repeat the string in search of the maximum length of each prefix / suffix. Example with string = "Obantao" and Pat 1 = "Bana" and Pat 2 = "SESESTA":
"Bana" = Pat 1 ^ in Straight Obaneta ^ ^ ^ | | | | | | | | | | | | | | | 0 ("") | | | | | | 0 ("") | | | | | 0 ("") | | | | 3 ("ban"). | | 2 ("BA"). | 1 ("B"). 0 ("") 0 ("") "ATSIS" = Reverse (Pat 2) reverse (string) O ATNAB He ^ ^ ^ ^ ^ ^ | | | | | | | | | | | | | | | 0 ("") | | | | | | 0 ("") | | | | | 1 ("A"). | | | 0 ("") | | | 2 ("AT"). | 1 ("A"). 0 ("") 0 ("")
Reverse by second array and amount.
0 0 2 3 0 0 0 + 0 0 1 0 2 1 0 0 ----------------- 0 0 2 2 5 1 0 | ^ | Maximum (argument = "bain" ++ reverse ("at")
Comments
Post a Comment