Pushdown automata
Pushdown automata as NFAs with a stack: the formal definition, instantaneous descriptions and moves, acceptance by final state and by empty stack (and the conversions between them), nondeterminism and epsilon-moves, designing PDAs for a^n b^n, ww^R, equal counts, balanced parentheses and i = j or j = k, tracing a computation, and what a PDA cannot do (compare more than one count).
Why it exists
A finite automaton has only a finite memory, so it cannot match . Add an unbounded stack and the machine can count: push one symbol for every , pop one for every . The resulting machine, the pushdown automaton (PDA), is exactly as powerful as a context-free grammar (next page). GATE asks: design a PDA, say which language a given PDA accepts, trace a computation, count stack operations, decide which languages a PDA can accept.
Prerequisites
A PDA is an NFA plus a stack (NFA; the stack operations are as in the stack ADT).
Precise definitions
A pushdown automaton is a 7-tuple :
- finite set of states, input alphabet, stack alphabet;
- finite subsets of (the transition function);
- start state, initial stack symbol (the bottom marker), accepting states.
A move: if then in state with input symbol next (or none read if ) and on top of the stack, the machine pops , pushes the string (written so that its first symbol ends up on top) and enters state . Every move pops exactly one symbol and pushes zero or more.
An instantaneous description (configuration) is : current state, unread input, stack contents (top first). if ; with in place of the input is unchanged.
Two standard acceptance conditions:
- by final state: (the stack is ignored);
- by empty stack: (the final states are ignored).
Theorem. The two conditions define the same class of languages: from a PDA accepting by final state one builds one accepting by empty stack with the same language, and conversely (constructions below; checked on named and random PDAs).
A PDA is deterministic (DPDA) if for every state, input symbol and stack top at most one move applies, counting -moves: if is non-empty then is empty for every . Otherwise it is nondeterministic; a string is accepted if some computation accepts.
How it works
Reading a computation
The first machine accepts () and is deterministic. States (start, accepting: the empty string), (reading 's), (reading 's), (accepting). Moves:
- : first : push above the bottom marker;
- : every further pushes another ;
- and : every pops an ;
- : when only the marker is left, accept.
Computation on (the stack is shown with its top at the left; the table is the transition function, the outlined cell is the move used):
A PDA for a^n b^n reading aaabbb: start
Parser run by a script, not typedPushdown automaton, one accepting computation (a shortest one found by breadth-first search over configurations). The stack is on the left with its top first; the unread input is on the right.
| state, top | a | b | ε |
|---|---|---|---|
| q0, Z | q1,AZ | ||
| q1, A | q1,AA | q2,ε | |
| q2, A | q2,ε | ||
| q2, Z | q3,Z |
Step 0
The machine starts in state q0 with the stack Z (only the bottom marker) and the whole input unread. The stack is shown with its top at the left.
The stack grows to symbols (the markers and ) and the machine accepts when the stack is back to with all input read. It rejects (it ends with an left, no move to ), (the third finds on top and no move) and (no move from on ).
Nondeterminism: even palindromes
A PDA cannot know where the middle of is. It guesses: while reading the first half it pushes each symbol; at some moment it takes an -move into the second half, where it pops a symbol for every matching input symbol.
- and for : push the symbol read;
- for : guess the middle;
- : match and pop; , accepting.
On one computation accepts (guessing the middle after ):
A PDA for w w^R reading abba (it guesses the middle): start
Parser run by a script, not typedPushdown automaton, one accepting computation (a shortest one found by breadth-first search over configurations). The stack is on the left with its top first; the unread input is on the right.
| state, top | a | b | ε |
|---|---|---|---|
| q0, a | q0,aa | q0,ba | q1,a |
| q0, b | q0,ab | q0,bb | q1,b |
| q0, Z | q0,aZ | q0,bZ | q1,Z |
| q1, a | q1,ε | ||
| q1, b | q1,ε | ||
| q1, Z | q2,Z |
Step 0
The machine starts in state q0 with the stack Z (only the bottom marker) and the whole input unread. The stack is shown with its top at the left.
All computations are followed at once in the table of configurations. After the whole input there are of them; one is in the accepting state with the stack :
All computations of the w w^R automaton on abba at once: start
Computed by a script, not typed| input read | configurations (state, stack with the top first) | number | accepting? |
|---|---|---|---|
| nothing read | |||
| after a | |||
| after ab | |||
| after abb | |||
| after abba |
Step 0
Nondeterminism means many computations in parallel. After each input symbol the table lists every configuration that some computation can be in (ε-moves included). The string is accepted if some computation ends in an accepting configuration.
This machine is nondeterministic ( and both apply). That is not an accident: no DPDA accepts the set of even palindromes (textbook theorem, proved on the next batch's page).
More machines (each verified on all strings up to a length bound)
- Equal numbers of and (any order): one state; the stack holds the surplus. On : pop a if one is on top (cancel), otherwise push ; on : pop an if one is on top, otherwise push . Accept when only is left (and the input is used up).
- Balanced parentheses: push a marker on , pop on ; accept with only left.
- with or : at the start guess which of the two comparisons to make (an -move into one of two branches): branch one pushes for , pops for , ignores ; branch two ignores , pushes for , pops for .
From final state to empty stack, and back
- Final state empty stack. Put a new bottom marker under and a new start state that pushes above it. From every accepting state add an -move to a new state that pops everything (including ). The new marker stops the machine from emptying its stack by accident.
- Empty stack final state. Add a new marker under ; whenever becomes the top (the old stack is empty), move to a new accepting state.
What a PDA cannot do
One stack gives one unbounded counter that can be compared once. and (no reversal) are not accepted by any PDA (the pumping lemma for CFLs, later; quoted here). A PDA with two stacks is as powerful as a Turing machine (textbook theorem, quoted). A PDA that does not use its stack is just an NFA, so every regular language is accepted by a PDA.
Worked examples
EX 1Which language
EasyA PDA has states with accepting. It pushes on every read in , on the first it pops an and goes to , on every further it pops an , and from with only left it moves by to . It accepts (checked on all strings up to length ); the empty string is rejected because is not accepting. Always check whether the start state is accepting and whether the machine can go back to pushing after it started popping.
EX 2Trace a computation
EasyFor the machine on : : five moves, accepted because and the input is used up.
EX 3Design: a^n b^(2n)
MediumPush two symbols for every (or one symbol for each and then pop one symbol for every two 's using an extra state). With the first method: , , , , then an -move on to an accepting state. The stack reaches height (and the machine needs the extra -moves on , from for and from at the end; checked on all strings up to length ).
EX 4Final state versus empty stack
MediumThe language by empty stack with two states: , , , , (for ) and (for the end): the last move pops and the stack is empty. No final states are needed.
EX 5Typical questions
GATE level(a) "Which is accepted by a PDA: , , ?" The first and third. (b) "Is every regular language accepted by a PDA?" Yes. (c) "Acceptance by final state versus empty stack:" equivalent in power for nondeterministic PDAs. (d) "A PDA accepts :" yes (a nondeterministic choice); it does not need to count both at once. (e) "Is accepted by a DPDA?" Yes. The deterministic machine uses two states: (accepting) means "only the bottom marker is on the stack", means "surplus present"; the first surplus symbol is a special bottom-level symbol, so popping it returns to (verified on all strings up to length ). (f) "Maximum stack height of the machine on :" .
Cheat box
Cheat box
- PDA ; a move pops one symbol, pushes a string, may read or not read input.
- Accept by final state (stack ignored) or by empty stack (states ignored); equivalent.
- : push for , pop for (deterministic). : push, guess the middle (-move), pop (nondeterministic). Counts compared once only.
- and are not PDA languages. Regular DPDA languages PDA languages.
- Deterministic: no -move together with an input move on the same state and stack top.
Traps and GATE patterns
Connections
Unlocks
Across subjects
The machines of this page are the machines of the next one: every grammar has a PDA and every PDA a grammar (PDA and CFG); the deterministic subclass matters for parsing (deterministic versus nondeterministic PDA); the NFA is a PDA that ignores its stack (NFA).
PYQs
6 previous year questions from your book. I re-solved each one myself (5 by running or simulating, 1 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider the pushdown automaton (PDA) P below,
which runs on the input alphabet {a, b}, has stack
alphabet {⊥, A}, and has three states {s, p, q}, with s
being the start state. A transition from state u to state v,
labelled c/X/γ, where c is an input symbol or , X is a
stack symbol, and γ is a string of stack symbols,
represents the fact that in state u, the PDA can read c
from the input, with X on the top of its stack, pop X from
the stack, push in the string γ on the stack, and go to state
v. In the initial configuration, the stack has only the
symbol ⊥ in it. The PDA accepts by empty stack.
Which one of the following options correctly describes the
language accepted by P?- (a){ambn | 1<=m and n<m}
- (b){ambn | 0<=n<=m}
- (c){ambn | 0<=n and 0<=m}
- (d){am| 0<=m} U {bn | 0<=n}
In a pushdown automaton P=(Q,Σ,Γ,δ,q0,F), a
transition of the form,
where p, q∈Q, a ∈ Σ ∪ {ε}, X , Y ∈ Γ∪ {ε},
represents:(q,Y) ∈ δ(p,a,X)
Consider the following p ushdown automaton over the
input alphabet Σ={a,b} and stack alphabet Γ={#,A}.
The number of strings of length 100 accepted by the above
pushdown automaton is ___________Consider the transition diagram of a PDA given below
with input alphabet Σ = {a,b} and stack alphabet Γ =
{X,Z}. Z is the initial stack symbol. Let L denote the
language accepted by the PDA.
Which one of the following is TRUE?- (a)L = {anbn | n>= 0} and is not accepted by any finite automata
- (b)L = {an| n >= 0} {anbn ∪ | n > =0} and is not accepted by any deterministic PDA.
- (c)L is not accepted by any Turning machine that halts on every input.
- (d)L = {an| n >= 0} {anbn ∪ | n > =0} and is deterministic context-free. THEORY OF COMPUTATION
Consider the NPDA 〈Q = {q0, q1, q2}, Σ = {0, 1}, Γ =
{0, 1, ⊥}, δ, q0, ⊥, F = {q2}〉, where (as per usual
convention) Q is the set of states, Σ is the input alphabet,
Γ is stack alphabet, δ is the state transition function, q0
is the initial state, ⊥ is the initial stack symbol, and F is
the set of accepting states, The state transition is as
follows:
Which one of the following sequences must follow the
string 101100 so that the overall string is accepted by
the automaton?- (a)10110
- (b)10010
- (c)01010
- (d)01001
Consider the pushdown automaton (PDA) below which
runs over the input alphabet (a,b,c). It has the stack
alphabet { Z0,X } where Z0 is the bottom-of-stack marker.
The set of states of the PDA is (s,t,u,f) where s is the start
state and f is the final state. The PDA accepts by final state.
The transitions of the PDA given below are depicted in a
standard manner. For example, the transition (s,b,X)-
(t,XZ0) means that if the PDA is in state s and the symbol
on the top of the stack is X, then it can read b from the
input and move to state t after popping the top of stack and
pushing the symbols Z0 and X (in that order) on the stack.
(s,a,Z0) → (s,XXZ0)
(s,∈,Z0) → (f,∈)
(s,a,X) → (s,XXX)
(s,b,X) → (t,∈)
(t,b,X) → (t,∈)
(t,c,X) → (u,∈)
(u,c,X) → (u,∈)
(u,∈,Z0) → (f,∈)
The Language accepeted by the PDA is- (a). {albmcn | l=m=n }
- (b). {albmcn | l=m}
- (c). {albmcn | 2l=m+n}
- (d). {albmcn | m=n}
Let P be a non-deterministic push-down automaton
(NPDA) with exactly one state, q, and exactly one symbol
Z, in its stack alphabet. State q is both the starting as well
as the accepting state of the PDA. The stack is initialized
with one Z before the start of the operation of the PDA.
Let the input alphabet of the PDA be Σ. Let L(P) be the
language accepted by the PDA by reading a string and
reaching its accepting state. Let N{P} be the language
accepted by the PDA by reading a string and emptying its
stack. Which of the following statements is TRUE?- (a)L(P) is necessarily Σ* but N{P} is not necessarily Σ*.
- (b)N{P} is necessarily Σ* but L(P) is not necessarily Σ*.
- (c)Both L(P) and N(P) are necessarily Σ*.
- (d)Neither L(P) nor N(P) are necessarily Σ*
Self-check
Question 1
Why can a PDA accept but a DFA cannot?
Show answerHide
The stack remembers , which needs unbounded memory; a DFA has finitely many states.
Question 2
What is the maximum stack height of the machine above on ?
Show answerHide
(five markers and the bottom marker ).
Question 3
Where does the PDA for use nondeterminism?
Show answerHide
In the -move that guesses the middle of the string.
Question 4
How do you turn a PDA that accepts by final state into one that accepts by empty stack?
Show answerHide
Add a new bottom marker, a new start move that pushes above it, and -moves from every accepting state to a state that pops everything.
Revision card
One-screen revision
- PDA = NFA + stack; move pops one symbol and pushes a string; configurations .
- Final state or empty stack accept the same languages.
- DPDA: no conflict between and input moves; needs guessing.
- Cannot do or ; regular PDA.
References
- ·Sipser, Introduction to the Theory of Computation (3rd edition), Section 2.2 (pushdown automata)
- ·Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation (3rd edition), Chapter 6 (pushdown automata), Sections 6.1 to 6.3
Verification
scripts/enum-checks/toc_cfg.py: the six PDAs on this page (a^n b^n deterministic by final state and by empty stack, even palindromes, equal numbers of a and b, balanced parentheses, i = j or j = k) accept exactly the strings of independent predicates on all strings up to length 10 (12 for parentheses, 9 for the three-symbol language); the search for an accepting computation is a breadth-first search over configurations (state, unread input, stack) with a bound on the stack height; the deterministic one has no state and stack top with both an epsilon move and an input move; the stack of the a^n b^n machine reaches height n + 1 for n = 0..7; final-state PDAs were converted to empty-stack PDAs and back (named and 100 random PDAs) with the same language on all strings up to length 5 to 8; the computation traces were replayed against the transition tables. Facts about PDAs with two stacks and about the limits of PDAs are textbook statements, quoted. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (state counts, derivations, parse-tree and move counts, decomposition counts); tables and animations are machine output and were read, not re-run; One unclear sentence (the one-state machine for equal numbers of a and b) and the wording of the empty-stack example were rewritten. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)