GATE / CS ARCHIVE

GATE CSE 2021 SET 1 / QUESTION 51

GATE CSE 2021 Set 1 Q51

Theory of Computation · Pushdown Automata · Full GATE CSE 2021 Set 1 paper

GATE 2021 Set 1, Q51 2 marks · NAT
Report issue

Pushdown Automata

Question 51, GATE 2021: A PDA has states q0,q1,q2,q3, start q0 and only final state q3, input {a,b} and stack alphabet {#,A}. Transition label input,pop→push is used, with ε meaning no input/pop/push. Transitions: q0→q1: ε,ε→#; q1 loop: a,ε→A; q1→q2: ε,ε→ε; q2 loop: b,A→ε; q2→q3: ε,A→A. There are no other transitions. How many length-100 strings are accepted by final state?
Tap to enlarge
Answer & solution

Official answer: 50

The PDA first pushes its bottom marker, then pushes one A for each initial a. In the second phase it pops one A for each b. Reaching the final state requires an A still on top, so the language is am bn with m>n>=0. For total length 100, n can be any integer from 0 through 49, with m=100-n. Each choice determines one string, giving 50. The accepting-state transition preserves that remaining A; acceptance is by final state rather than empty stack.

While reading a's, the stack contains one A per a above #. After switching to q2, each b removes one A and no a-transition exists, enforcing the order a* b*. The final ε-transition tests and preserves an A, requiring strictly more a's than b's. For length 100, m+n=100 and m>n give 100−n>n, so n<50. Each n=0,...,49 gives one word a100−nbn, including a100; equality at n=50 is not accepted.

Original paper, page 40 · Answer key