GATE Computer ScienceVery hardGATE CS (PYQ pattern)

L = { w ∈ {a, b}* : the substring ab occurs an odd number of times AND the substring ba occurs an odd number of times }. How many states does the minimal complete DFA for L have?

  1. A. 4
  2. B. 16
  3. C. 9
  4. D. 8

Correct answer: C. 9

#ab − #ba is 0 if w starts and ends with the same letter, ±1 otherwise; so both are odd iff #ab is odd and w begins and ends with the same letter. A DFA must remember the first letter, the last letter and the parity of #ab. The classes have representatives ε, a, b, ab, ba, aba, bab, abab, baba, with aba and bab accepting — 9 states.

More Theory of Computation questions

Exams that ask this topic