AC Automaton---fail pointer

Source: Internet
Author: User

Let's see how the Trie tree is constructed before you see it.

The words on the tree are (from top to bottom)

{He, hers, his, she}

Divided into 3 layers as shown in the figure

See the third floor

It's "she."

which

①s point to Root

②h first find the fail pointer of S, found to be the number NO. 0 pointer, not h,

Then H is not happy, then ask s the fail pointer root: "You have no son and I named H."

Root says: "Yes, you point to him."

Then H was pleased to point to the first line of H.

③e began to look, first asked his father H: "Your fail pointer pointing to who"

H said, "The first line on the chart, the H ah."

Then E went to the top of the line and asked, "Do you have a son like me?"

On the first line of the picture, the H said, "Yes, he's the address xxx."

The last e's fail pointer points to the XXX address, which is the first line of the E.


found that, if a string to find the third line after the E character characters mismatch, it means that he should have a ' he ' in front

The failed pointer to just e points to the E of the first line of ' he ... '.

This saves time by not having to look for it again from H, but then the first line of E to continue looking backwards.

AC Automaton---fail pointer

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.