To find a child string
There are 5 kinds of minimal operations subsets in data structure: string assignment, string comparison, string length, string connection, substring , and other operations can be implemented on this subset.
- Pattern matching of strings in data structure
KPM Pattern Matching algorithm
A basic pattern matching algorithm
//substring the position of a string in string
functionsubString (String, subString) {varI=0,j=0;
When I or j out of range exits while(i<string.length&&j<substring.length) { if(string[i]==Substring[j]) { ++i;++J}Else{
When the match is unsuccessful, I is moved from the start position to one I=i-j+1;j=0; } }
If J is out of range then return i-j, if I out of range means not found
if (j>=substring.length) return i-J; Else return false;
}
See, whenever the match is unsuccessful, I always return to the beginning of this match
KPM, an improved pattern matching algorithm to solve the I-back problem
This leads to a very important question ' including the prefix ',
Take substring= 'abcabcacab', for example. Prefix string ' abca ' = ' abc[abca]Cab ' in square brackets, if the match fails at c after the string, simply make the prefix string a with a in parentheses, and then continue to match from C where the match failed.
So we need to find out the value of the substring to move back to the j-k+1 after the match failure in J
Suppose that F (j) represents the largest k in the substring prefix preceded by J, such as ' ABCABCA ', k-1=1,4, i.e. the maximum K is 5;f (8) =5
So ' ABCABCACab ', F (9) =f (8) + (Substring[5]? ==SUBSTRING[8]), if equal, then f (9) = 6; if not equal F (9) requires recalculation, because C of substring[9-1] causes the maximum inclusion prefix to no longer be ABCA, but one containing prefix string that has the end of C. There is actually no such string;
blog.csdn.net/yukuninfoaxiom/article/details/6057736
blog.csdn.net/joylnwang/article/details/6778316/
http://www.rudy-yuan.net/archives/182/
Www.webhek.com/misc/comparison-sort
- Compiler principle Lexical analyzer
Nfa/dfa
Find the substring-kpm pattern matching-NFA/DFA