Similar questions 1 more →
Finite Automata


Shared context
Alphabet {a,b}; accept precisely strings containing baab as a contiguous substring.
Answer & solution
Answer: Start q0; accepting q4. Transitions on (a,b): q0→(q0,q1), q1→(q2,q1), q2→(q3,q1), q3→(q0,q4), q4→(q4,q4). (no official key was published)
Step through it (2 parts)
1. Use states to remember the longest suffix of the input read so far that is also a prefix of baab: q0 remembers ε, q1 remembers b, q2 remembers ba, and q3 remembers baa. q4 means the complete substring has already occurred.
2. From q0, a contributes no matching prefix and b starts one: δ(q0,a)=q0, δ(q0,b)=q1. From q1, a extends b to ba, while another b starts a fresh b: δ(q1,a)=q2, δ(q1,b)=q1.
3. From q2, a extends ba to baa; b leaves the suffix b. Thus δ(q2,a)=q3, δ(q2,b)=q1. From q3, b completes baab and a destroys every nonempty matching suffix: δ(q3,b)=q4, δ(q3,a)=q0.
4. Both transitions from q4 loop to q4, since later symbols cannot remove an occurrence already seen. Set start q0 and accepting set {q4}. The trace baab is q0→q1→q2→q3→q4; baa alone ends in nonaccepting q3.