GATE Computer ScienceHardGATE CS (PYQ pattern)

Occurrences of aa may overlap (aaa contains two). How many states does the minimal complete DFA for { w ∈ {a, b}* : w contains EXACTLY two occurrences of aa } have?

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

Correct answer: D. 7

Count occurrences 0, 1, 2 while remembering whether the last symbol is a: (0, last ≠ a), (0, last a), (1, last ≠ a), (1, last a), (2, last ≠ a), (2, last a), plus a dead state for a third occurrence. Both count-2 states accept and differ on suffix a, so 7 states.

More Theory of Computation questions

Exams that ask this topic