AC automation-Self-Summary

Source: Internet
Author: User

 

AC automatic machine algorithm Summary

No.1 what's Aho-corasick automatic?

A multi-mode string matching algorithm, which was developed by Bell Laboratory in 1975 and is one of the famous multi-mode matching algorithms.

To put it simply, KMP is used to match a pattern string. But if multiple pattern Strings need to appear in the same article nowAho-corasick AutomatonAlgorithm.

Do not naively think that the AC automatic machine is auto-accept, although it can make you ac some questions.

 

No. 2 my understanding about Aho-corasick automaton.

My understanding:Aho-corasick automaton = trie + KMP

In the KMP algorithm, when matching a single character, we only need to follow the text to linearly scan it, and then when the mismatch occurs in the middle, the next array will guide K back to the correct position for next matching.

But how do I match multiple mode strings? Isn't the trie tree a multi-mode match? If we combine the KMP and trie numbers, will it have unexpected results?

With these ideas, the AC automatic machine algorithm is generated in this way.

In the AC automatic machine, we first insert each pattern string into the word book, that is, create a trie tree, and then construct the Fail pointer and fail pointer, as the name implies, when the matching fails, a pointer inserted to each node of the trie tree to guide K Backtracking is the same as the next array in the KMP algorithm.

The construction of the Fail pointer can be understood only by Li Xiang's PPT.

PPT download link: http://wenku.baidu.com/view/93af2c936bec0975f465e2f1.html

After constructing the Fail pointer, we will use the article to match the trie tree.

The matching process is divided into two situations: (1) the current character matches, indicating that there is a path along the tree edge from the current node to reach the target character. In this case, you only need to continue matching along the path to the next node, the target string pointer moves to the next character to continue matching. (2) If the current character does not match, the character pointing to the failed pointer of the current node continues matching. The matching process ends with the pointer pointing to the root. Repeat any of the two processes until the pattern string ends.

Check the detailed process of pattern matching. The pattern string is yasherhs. For I = 0, 1. There is no corresponding path in trie, so no operation is performed. When I = 2, 3, 4, the pointer P goes to the lower left node E. Because the Count information of node e is 1, CNT + 1, and the count value of node e is set to-1, which indicates that the word has already been changed to prevent repeated counting, finally, temp points to the failed pointer of node e to continue searching, and so on. Finally, temp points to root and exits the while loop. In this process, count is increased by 2. 2 words she and he are found. When I = 5, the program enters row 5th, and P points to the node with its failure pointer, that is, the e node on the right, and then points to the r node in row 6th, the Count value of the r node is 1, so that count + 1 is collected until temp points to root. When I = 6, 7, no matching is found, and the matching process ends.

This process is very similar to the KMP algorithm. Of course, this step is very flexible. We need to do more questions to improve the proficiency.

 

No. 3 some good selection of standard exercises

1. HDU 2222

2. HDU 3695 computer virus on planet Pandora

3. poj 4052 hrinity (Jinhua Invitational competition I)

4. zoj 3430 detect the virus

5. spoj 7758. Growing strings

6. HDU 4417 GRE words

8. hnu 10104 Virus

10. hnu 11187 emoticons :-)

11. zoj 3545 rescue the rabbit

12. HDU 3341 lost's revenge

13. zoj 3535 Gao the string II

15. HDU 3962 microgene

16. Big field 2434 a raccoon's typewriter

17. HDU 3247 resource archiver

18. zoj 3494 BCD code

 

Iii. Comprehensive questions

HDU 3247. Resource archiver

HDU 3341. Lost's revenge

Tags: Status compression and variable-base Encoding

Hoj 2951. Writing robot/HDU 3505.

Tags: largest weighted closed subgraph

Zerojudge b179. empty tank cans

Tags: Automatic DP, fail pointer Transfer

Codechef July challenge 2012. favourite numbers

Tags: Binary answer, digital DP, Construction Scheme

Andrew stankevich's contest #2, problem A, non absorbing DFA

Preprocessing, DP, and high precision

Spoj. 9941. GRE words/HDU 4117

  

 

AC automation-Self-Summary

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.