Theory of Computation · Pushdown Automata
PDA for a^n b^m c^n
Overview
A pushdown automaton (PDA) accepts the language .
The a's are counted on the stack and matched one-to-one against the c's, while the b's are ignored entirely; separate states are required to remember that the b-block has been passed and the c-block has begun.
Key concepts
- Language: — the a's must be matched (counted) against the c's, while the b's are simply ignored: they are neither pushed nor popped.
- Stack alphabet: , where is the bottom marker. Push for each a, pop for each c, never touch the stack for b's.
- Phase 1 — push all a's: start in the initial state with on the stack; on reading an a, push ; repeat for every a, so after the a-block the stack holds .
- Phase 2 — skip the b's: on seeing the first b with on top, leave the stack unchanged (no push, no pop) and move to the b-skipping state; in that state any number of further b's may be read with still on top, staying in the same state with the stack unchanged.
- Phase 3 — match c's against a's: on reading a c with on top, replace by (pop it); keep doing this for every c, popping one per c.
- Phase 4 — acceptance: when the entire input is over and the top of the stack is (all c's consumed and all 's popped), leave as it is and accept.
- Why three states (plus the initial state) are compulsory:
- After seeing a b, the machine must move to a new state to remember "a b has been seen, so no a is allowed after this."
- After seeing a c, the machine must move to a new state to remember "a c has been seen, so no b is allowed after this."
- Popping cannot be done in the same state: if popping were done in the same state, a b could appear after a c and there would be confusion about which symbol is being matched. Hence the separate states.
How it works
- Start in the initial state with (bottom marker) on the stack.
- On reading an a, push onto the stack; repeat for every a, so after the a-block the stack holds .
- On seeing the first b with on top of the stack, leave the stack unchanged (do not push, do not pop) and move to the next state.
- In this state, any number of further b's may be read with still on top; again leave the stack as it is and move to the next state.
- In the c-matching state, on reading a c with on top of the stack, replace by (pop it); keep doing this for every c, popping one per c.
- When the entire input is over and the top of the stack is (all c's consumed and all 's popped), leave as it is and accept.
Drawing the diagram…
Formulas
- — the language accepted by the PDA.
- Stack after the a-block: — one pushed per a, above the bottom marker.
- Stack operation for a: push .
- Stack operation for b: no change (leave ).
- Stack operation for c: pop (replace by ).
- Acceptance condition: input exhausted and stack top .
Worked examples
Transition list (state, input, stack top new state, stack operation). Let = initial, = first b seen, = b's being skipped, = c-matching, = accepting.
| State | Input | Stack top | New state | Stack operation |
|---|---|---|---|---|
| a | push | |||
| a | push | |||
| b | no change (leave ) | |||
| b | no change (leave ) | |||
| b | no change (leave ) | |||
| c | pop (replace by ) | |||
| c | pop (replace by ) | |||
| — (input over) | leave , accept |
Trace for the string (, ):
- , read a, stack top push . Stack: .
- , read a, stack top push . Stack: .
- , read b, stack top go to , stack unchanged. Stack: .
- , read b, stack top go to , stack unchanged. Stack: .
- , read c, stack top go to , pop . Stack: .
- , read c, stack top stay in , pop . Stack: .
- , input over, stack top accept.
Revision summary
- The a's are counted on the stack and matched one-to-one with the c's; the b's are ignored entirely — no push, no pop, no counting.
- The stack alphabet is : push for each a, pop for each c, never touch the stack for b's.
- Two working states after the initial state suffice: one to skip the b's (entered on the first b, looping on further b's) and one to match c's — because the PDA must forbid an a after a b and forbid a b after a c.
- Popping in the same state as b-skipping would allow a b after a c and cause confusion, so c-matching must be in its own state.
- Acceptance happens only when the input is exhausted and the stack top is (all a's matched by c's).
- The language requires : at least one a, one b and one c.
Previous-year exam insights
- A language is context-free iff some PDA accepts it; a PDA accepts by final state or by empty stack, and the two acceptance modes are equivalent in power (each can be converted to the other).
Asked inGATE 2016GATE 2023 - Pumping lemma for CFLs: for any CFL there is a pumping length p such that every string of length ≥ p can be written uvwxy with |vwx| ≤ p, |vx| ≥ 1, and y in L for all i ≥ 0;
use it to prove languages like { } or { } non-context-free.
Asked inGATE 2025 - A language of the form { } with a single linear constraint among the exponents (e.g. i = k, or i + k = j + l) is context-free, while two independent equality constraints (e.g. i = k and j = l simultaneously, or i = j = k) generally make it non-context-free.
Asked inGATE 2026 - Deterministic PDAs are strictly weaker than nondeterministic PDAs; languages such as { } union { } or even-length palindromes are context-free but not accepted by any DPDA.
Asked inGATE 2016 - A PDA with a single stack cannot count two independent quantities; matching one symbol block against another (one push/pop pair) is fine, but matching three blocks pairwise requires more than one stack.
Asked inGATE 2025GATE 2026 - Standard PDA transition notation: a transition (u, c, X) → (v, gamma) reads input c (or epsilon), requires stack top X, moves to v and replaces X by the string gamma (gamma = epsilon means pop, gamma = X means no change, gamma = XA means push A).
Asked inGATE 2023