GATE / CS ARCHIVE

SIMILAR QUESTIONS / THEORY OF COMPUTATION

Build a DFA that forbids a consecutive-symbol run

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

How these are solved

Track the trailing run length and enter a rejecting sink once the forbidden run is reached. The historical question asks for the transition diagram over a/b; the newer one asks the minimum state count over 0/1.

2 marks · NAT
Report issue

Finite Automata

Question 63, GATE 2023: Find the minimum number of states of a complete DFA over {0,1} accepting strings that never contain three consecutive 1s.
Tap to enlarge
Answer & solution

Official answer: 4

Step through it (2 parts)

Use three accepting states tracking the trailing run of ones of lengths 0, 1, 2, and a rejecting trap after the third consecutive one. A zero resets each nontrap state to run length 0; a one advances the run or reaches the trap. All four states are reachable. The trap differs from the others on the empty suffix. For two run lengths i<j among 0, 1, 2, append 3-j ones: the state j rejects but state i still accepts. Thus all four are pairwise distinguishable and the DFA is minimal.

Teaching detail. Name states q0,q1,q2,dead by the count of trailing 1s until a forbidden run has occurred. On 0, q0,q1,q2 go to q0; on 1 they go to q1,q2,dead respectively. dead loops on both symbols because an earlier occurrence of 111 can never be undone by later zeros. q0,q1,q2 accept, including q0 for ε. Reachability witnesses are ε,1,11,111. A construction alone proves an upper bound of four; the distinguishability argument is required to exclude every possible smaller DFA.

Original paper, page 67 · Answer key

2 marks · MCQ
Report issue

Complete DFA avoiding three consecutive zeros

Finite Automata

Question 46, GATE 2012: Complete a DFA for binary strings in which every length-three substring has at most two zeros (so 000 is forbidden). All strings shorter than three are accepted. States ε (initial),0,1,00,01,10,11 are accepting; q is rejecting. Existing transitions: ε--0→0, ε--1→1, 0--0→00, 0--1→01, 1--0→10, 1--1→11, 01--0→10, 10--1→01, 11--1→11, q--0,1→q. Which list supplies the missing arcs? Each triple means (source,input,target).
(A) (00,1,00),(00,0,01),(01,1,11),(10,0,00),(11,0,10).
(B) (00,0,01),(00,1,q),(01,1,01),(10,0,11),(11,0,01).
(C) (00,1,01),(00,0,q),(01,1,01),(10,0,10),(11,0,01).
(D) (00,1,01),(00,0,q),(01,1,11),(10,0,00),(11,0,10).
Tap to enlarge
Your answer
Answer & solution

Official answer: D

The forbidden length-three substring is exactly 000. The two-symbol states retain the last two symbols until the rejecting sink q is reached. Missing transitions are δ(00, 0)=q, δ(00, 1)=01, δ(01, 1)=11, δ(10, 0)=00, and δ(11, 0)=10. These are precisely table D. Every nonsink state accepts, including the states for strings shorter than three symbols.

Check: Appending 0 to suffix 00 creates forbidden 000, requiring the sink. Appending 1 to 00 leaves suffix 01; appending 1 to 01 leaves 11; appending 0 to 10 leaves 00; appending 0 to 11 leaves 10. This derives every missing arc rather than matching only one table entry.

Original paper, page 11 · Answer key

5 marks · Descriptive
Report issue

DFA excluding three consecutive b characters

Finite Automata

Question 27, GATE 1993: Draw a DFA over {a,b} accepting exactly strings with no substring bbb.
Tap to enlarge
Answer & solution

Answer: States q0,q1,q2 accepting, qD rejecting; start q0; a resets q0 before death; b advances q0→q1→q2→qD; qD loops. (no official key was published)

Step through it (2 parts)

While no forbidden substring has appeared, only the length of the trailing run of b characters matters. State q0 means zero trailing b's, q1 one, and q2 two. A third consecutive b makes the input permanently unacceptable, represented by rejecting sink qD.

Transition diagram as a complete edge list:
q0 --a--> q0; q0 --b--> q1
q1 --a--> q0; q1 --b--> q2
q2 --a--> q0; q2 --b--> qD
qD --a,b--> qD.
Start at q0; accepting states are q0,q1,q2. In particular epsilon is accepted, and bb is accepted but bbb is not.

Induct on the processed prefix: before a forbidden block occurs, the named state records its trailing b count; an a resets that count and a b increments it. Upon reaching three, qD is entered and can never be escaped, so later a's cannot erase an earlier violation. This invariant proves both acceptance of every valid string and rejection of every invalid one. Four states are also minimal: qD differs from all accepting states on epsilon, and q0,q1,q2 can be distinguished by appending b or bb as appropriate.

Original paper, page 15