GATE / CS ARCHIVE

SIMILAR QUESTIONS / THEORY OF COMPUTATION

Push-pop to enforce more a than b

2 questions solved the same way, newest first. Back to Theory of Computation

How these are solved

Read a-block then b-block, pop for each b and require leftover a markers. One question counts fixed-length accepted words and the other identifies the language, so this is not a numbers repeat.

2 marks · MCQ
Report issue

Pushdown Automata

Question 40, GATE 2023: An empty-stack-accepting PDA starts in s with stack ⊥. In s, a/⊥/A⊥ and a/A/AA push one A. Transition s→p and the loop at p are b/A/ε. Transitions s→q and p→q are ε/A/ε. At q, ε/A/ε and ε/⊥/ε empty the stack. Describe its accepted language over {a,b}, consuming all input.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

In s each a pushes A. The first b moves to p and pops A, and further b’s pop more A. Entry to the cleanup state q requires an A at the stack top and pops it, so at least one A must remain after all input has been read. Then q removes the remaining stack symbols, including the bottom marker. Consequently input is aᵐbⁿ with m≥1 and 0≤n<m, option A. Equal counts leave only the bottom symbol in s/p and cannot enter q; epsilon is not accepted.

Teaching detail. After reading m a's, the stack is Am⊥. Reading n b's pops n A's, leaving Am−n⊥. The only gateway to the cleanup state consumes one further A without consuming input, which is possible precisely when m−n≥1. Cleanup cannot read more input, so all a's and b's must already have been consumed. Pure a strings with m≥1 are accepted via s→q; the empty string is not, because no transition from s pops ⊥ directly. The strict inequality n<m, not n≤m, is therefore essential.

Original paper, page 41 · Answer key

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