GATE Computer ScienceHardGATE CS (PYQ pattern)

A DPDA has start state q0, bottom symbol Z, accepting state set {q0} (acceptance by final state after the whole input is read) and transitions (stack top written first): δ(q0, a, Z) = (q1, AZ); δ(q0, b, Z) = (q1, BZ); δ(q1, a, A) = (q1, AA); δ(q1, b, B) = (q1, BB); δ(q1, a, B) = (q1, ε); δ(q1, b, A) = (q1, ε); δ(q1, ε, Z) = (q0, Z). (In q1 with Z on top only the ε-move exists, so the machine is deterministic.) How many strings over {a, b} of length at most 8 does it accept?

  1. A. 70
  2. B. 99
  3. C. 98
  4. D. 35

Correct answer: B. 99

The stack is a signed counter: A's record surplus a's, B's surplus b's, and whenever the counter returns to zero the ε-move takes the machine back to the accepting state q0. So it accepts exactly the strings with n_a = n_b, including ε (q0 is the start state). Count: C(0,0) + C(2,1) + C(4,2) + C(6,3) + C(8,4) = 1 + 2 + 6 + 20 + 70 = 99.

More Theory of Computation questions

Exams that ask this topic