GATE Computer ScienceHardGATE CS (PYQ pattern)

L = { w ∈ {a, b}* : #ab(w) ≡ #ba(w) (mod 3) }, where #ab and #ba count occurrences of these substrings. How many states does the minimal complete DFA for L have?

  1. A. 5
  2. B. 9
  3. C. 6
  4. D. 3

Correct answer: A. 5

Occurrences of ab and ba alternate, so #ab − #ba ∈ {−1, 0, 1}; being ≡ 0 (mod 3) means #ab = #ba, i.e. w is empty or starts and ends with the same letter. DFA: start (accepting), 'first a, last a' (accepting), 'first a, last b', 'first b, last b' (accepting), 'first b, last a' — 5 states.

More Theory of Computation questions

Exams that ask this topic