GATE Computer ScienceHardGATE CS (PYQ pattern)

How many states does the minimal complete DFA for { w ∈ {a, b}* : ab occurs EXACTLY twice as a substring } have?

  1. A. 5
  2. B. 7
  3. C. 6
  4. D. 8

Correct answer: B. 7

Track the count 0, 1, 2 and whether the last symbol is a (an ab can complete next): 3 × 2 = 6 states, plus a dead state once a third ab appears. Both count-2 states accept and differ (suffix b kills one). 7 states.

More Theory of Computation questions

Exams that ask this topic