GATE / CS ARCHIVE

GATE CSE 2025 SET 1 / QUESTION 50

Interpreting a suffix-tracking DFA

Theory of Computation · Finite Automata · Full GATE CSE 2025 Set 1 paper

GATE 2025 Set 1, Q50 2 marks · MSQ
Report issue

Finite Automata

Question 50, GATE 2025: A DFA over {a,b} has states q0,q1,q2,q3, start q0 and sole accepting state q3. Transitions on (a,b) are q0→(q0,q1), q1→(q2,q1), q2→(q0,q3), q3→(q2,q1). Which language does it recognize? A words with an even number of b’s; B words containing bab; C words ending in bab; D words avoiding aba.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: C

Approach: Assign each state the longest suffix of the input read so far that is also a prefix of the pattern bab.
The prefixes are ε,b,ba,bab, corresponding respectively to q0,q1,q2,q3. At q0 an a leaves no nonempty matching suffix, while b starts the match. At q1 another b still leaves suffix b, while a extends it to ba. At q2, b completes bab, but a leaves no matching suffix and returns to q0.
After reaching q3, an a leaves suffix ba and returns to q2; a b leaves suffix b and returns to q1. Therefore acceptance records that the current complete word ends in bab, not merely that bab appeared at some earlier position. This proves C.
B fails because baba contains bab but ends at nonaccepting q2. A fails because the empty word has an even b-count but is rejected. D fails because a avoids aba yet is rejected.

Original paper, page 50 · Answer key