The time complexity of the pattern matching of the KMP algorithm is much better than the simple pattern matching, but the improvement of the time efficiency is a precondition, that is: the repetition rate of the pattern string is very high, otherwise its efficiency will not be highlighted. In practical applications, the KMP algorithm is not a very high rate of use of an algorithm, but its core point is the use of high, that is the next prefix array to solve the idea. In this note, we take out the solution of the prefix array separately.
1. Definition of next prefix array
2. Next array of brute force solutions
The main ideas of this approach are:
In order to solve the value of NJ, all the prefixes and suffixes are identified and then matched from the largest, until the appropriate longest common prefix suffix is found. If not, then the value of NJ is 0.
How to select the front and back prefixes:
The brute force algorithm is the one that constantly matches the maximum prefix and suffix.
Algorithm Description:
(1) By definition, initialize N[0] =–1
(2) from the position of the pattern string subscript 1, sequentially traversing the entire pattern string. For each character, look for the maximum common prefix suffix of the string in front of it, and count the number of characters as next[j], if there is no public suffix, Count next[j]= 0
https://www.zybuluo.com/wzhang1117/note/27431
KMP algorithm of the outside chapter