GATE Computer ScienceHardGATE CS (PYQ pattern)

A nondeterministic PDA (start q0, bottom symbol Z, final state qf, acceptance by final state) has the rules: in q0 it pushes A or B for each a or b read; in q0 it may either make an ε-move to q1 or, reading one symbol, jump to q1 without pushing it; in q1 it pops A on a and B on b; and in q1 it moves to qf on ε when Z is on top. How many strings of length at most 8 over {a, b} does it accept?

  1. A. 31
  2. B. 61
  3. C. 62
  4. D. 60

Correct answer: B. 61

It accepts exactly the palindromes: even ones through the ε guess and odd ones through the one-symbol skip. Counting 2^⌈k/2⌉ for k = 0..8 gives 1+2+2+4+4+8+8+16+16 = 61.

More Theory of Computation questions

Exams that ask this topic