KMP algorithm of the outside chapter

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.