Long talk KMP algorithm

Two strings:

    Pattern strings: ababcaba

    Text string: ababcabcbababcabacaba

KMP algorithm action: Fast pattern matching string to the text string

 

If the law is exhaustive way:

 

 We have found that this ratio is very low efficiency.

So we need to use a high-efficiency mode algorithm: KMP algorithm.

 

We have seen above method of exhaustion, was a bit moved. You can not move more than once on the list. As follows:

 

 

 

 

 

 

So why can move it like this?  Pattern string from moving to the right = the number of characters matched - maximum length mismatch on a character corresponding to the character

So we have to find out how the value of the maximum length of each do it? We come to it.

 

 

So, using the KMP algorithm to move bits:

 

Guess you like

Origin www.cnblogs.com/qzhc/p/11665886.html