GATE Computer ScienceHardGATE CS

Let L = { w ∈ {a, b}* : every prefix u of w satisfies |n_a(u) − n_b(u)| ≤ 2 }. How many states does the minimal complete DFA for L have?

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

Correct answer: B. 6

The running difference n_a − n_b can sit at −2, −1, 0, 1 or 2 (five states, all accepting and all distinguishable by runs of a's or b's of different lengths), and leaving that range sends the DFA to a single dead state: 5 + 1 = 6.

More Theory of Computation questions

Exams that ask this topic