GATE Computer ScienceVery hardGATE CS (PYQ pattern)

L is the set of strings over {a, b} such that in every prefix the number of a's and the number of b's differ by at most 2. How many states does the minimal complete DFA for L have (a dead state counts)?

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

Correct answer: C. 6

The DFA only needs the current difference #a − #b, which stays in {−2, −1, 0, 1, 2}: 5 accepting states, all distinguishable (from difference d the string a^(3−d) is accepted only for small enough d, and so on). One more step outside the band is fatal forever, so a dead state is needed: 6.

More Compiler Design questions

Exams that ask this topic