GATE / CS ARCHIVE

SIMILAR QUESTIONS / THEORY OF COMPUTATION

Remember partial matches of a fixed substring

2 questions solved the same way, newest first. Back to Theory of Computation

How these are solved

Track longest suffix that is a prefix of the forbidden/required word, including overlap fallback and a completed-match sink. Contains versus avoids changes accepting states, not the matching-memory construction.

1 mark · MCQ
Report issue

Finite Automata

Question 32, GATE 2015: Let Σ={0,1} and L be the language of the regular expression Σ*0011Σ*. What is the minimum number of states in a DFA recognizing the complement of L? Options: (A) 4; (B) 5; (C) 6; (D) 8.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. Writing states as matched-prefix lengths 0..4, transitions on (0,1) are 0→(1,0), 1→(2,0), 2→(2,3), 3→(1,4), 4→(4,4). For pattern containment only state 4 accepts; for its complement states 0..3 accept. For any i<j, the suffix completing prefix length j reaches state 4 from j but not from i, proving distinguishability.

2. A DFA tracks the longest suffix matching a prefix of 0011: lengths 0, 1, 2, 3, 4, with 4 an absorbing found-pattern state. These five states are pairwise distinguishable by completing the pattern; flipping accepting states recognizes avoidance of 0011 without changing minimal state count. Thus5, B.

Original paper, page 64 · Answer key

Descriptive
Report issue

DFA detecting substring baab

Finite Automata

Question 5(a), GATE 2001: Alphabet {a,b}; accept precisely strings containing baab as a contiguous substring.

Task: Construct a DFA for this language.
Question 5(a), GATE 2001: Alphabet {a,b}; accept precisely strings containing baab as a contiguous substring.

Task: Construct a DFA for this language.
Tap to enlarge
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.

Original paper, page 7