“Draw an NFA over a and b that accepts exactly the strings ending in ab: q0 loops on a and b, q0 can move to q1 on a, and q1 moves to accepting q2 on b.”
看懂背後的決策。
q0 keeps scanning while also guessing that an a starts the final suffix.
q2 is reached only after the guessed a is followed by b.
three states isolate the essential transition logic.
Use this pattern when an automaton needs to recognize a fixed ending without remembering the whole prefix.
常見問題
Why does q0 have two transitions on a?
One transition continues scanning the prefix and the other guesses that this a starts the final ab suffix.
Which strings are accepted?
Examples include ab, aab and bab. A string such as aba is not accepted because it does not end in ab.
Is q2 accepting only at end of input?
Yes. Acceptance requires a path to finish in q2 after the entire input has been read.