On this page
A finite automaton has a fixed number of states and no other memory, so it cannot count without limit (see our finite automata and regular languages guide). A pushdown automaton adds one thing: a stack.
What is a pushdown automaton?
A pushdown automaton is an automaton that uses a stack, a memory you can only change at the top: push an item on, or pop the top item off (Wikipedia: Pushdown automaton). At each step the machine looks at three things: its current state, the next input symbol (or none, called an ε-move), and the symbol on top of the stack. It then moves to a state and replaces that top symbol with zero, one or more symbols. Like plates at a hostel mess, you see and take only the top one: unlimited memory, used last in, first out.
How does a PDA accept aⁿbⁿ?
The language {aⁿbⁿ : n ≥ 1} is ab, aabb, aaabbb and so on. It is the standard example of a context-free language, generated by the grammar S → aSb | ab (Wikipedia: Context-free language). A finite automaton cannot accept it, because it would need a different state for every possible count of a's.
Our PDA has states q0 (reading a's) and q1 (reading b's), and stack symbols A (one per a) and Z (a bottom marker). The stack starts as Z.
In q0, reading a: push A and stay in q0.
In q0, reading b with A on top: pop A and move to q1.
In q1, reading b with A on top: pop A and stay in q1.
In q1, with Z on top and no input read: pop Z.
If no move applies, the machine is stuck and rejects. It accepts by empty stack: the input must be fully read when the stack becomes empty.
Trace it by hand on the input aabb, with the stack written top first:
Start: q0, stack Z.
Read a: q0, stack AZ.
Read a: q0, stack AAZ.
Read b: q1, stack AZ.
Read b: q1, stack Z.
ε-move: pop Z. Input finished, stack empty: accept.
Now aab: it ends in q1 with stack AZ, rule 4 cannot fire, so reject. abb: after ab the stack is Z and the last b finds no A, so reject. aba: q1 has no move on a, so reject. The states enforce the order; the stack does the counting.
Over all pushdown automata, accepting by empty stack and accepting in a final state define the same family of languages (Wikipedia: Pushdown automaton), so pick whichever is simpler.
Are pushdown automata equivalent to context-free grammars?
Yes. The set of context-free languages is identical to the set of languages accepted by pushdown automata (Wikipedia: Context-free language). Every context-free grammar can be turned into an equivalent nondeterministic PDA (Wikipedia: Pushdown automaton). For rules, parse trees and ambiguity, read our guide to context-free grammars.
One catch: not all context-free languages are deterministic. Even-length palindromes over two letters, such as abba, are context-free, but no deterministic PDA recognises them (Wikipedia: Pushdown automaton). Intuitively, it cannot tell where the middle is.
Why can't a PDA accept aⁿbⁿcⁿ?
Push for each a, pop for each b, and when the c's arrive the stack is empty and the count is gone. One stack checks one pair of counts, not three.
The formal proof applies the pumping lemma for context-free languages, from Bar-Hillel, Perles and Shamir's 1961 paper, to the string aᵖbᵖcᵖ (Wikipedia: Pumping lemma for context-free languages). It says every long enough string in such a language has two pieces, inside a window of at most p symbols, that can be repeated together. In aᵖbᵖcᵖ that window cannot reach all three blocks, so repeating the pieces unbalances the counts. A Turing machine, with its read-write tape, handles aⁿbⁿcⁿ; see Turing machines explained.
Where are pushdown automata used in compilers?
When a compiler reads ((x + 1) * y), it must check that every bracket closes in order, the matching our PDA did with a's and b's. Deterministic PDAs are often used in parser design (Wikipedia: Pushdown automaton). One such method is LR parsing, introduced by Donald Knuth in 1965 (Information and Control, DOI 10.1016/S0019-9958(65)90426-290426-2)). An LR parser works from a parse stack, is deterministic, and produces a single parse without backtracking in linear time; parser generators such as Bison build it mechanically from the grammar (Wikipedia: LR parser).
How do you design your own PDA?
Say the language in words: what must match what?
Decide what one stack symbol stands for.
Use states for order, the stack for counting.
Run the four-string test.
Write the matching grammar and compare.
If states versus stack feels slippery, the Fermi Concept Library gives every concept in mathematics and computing its own lesson and its place in the map, so you can step back to finite automata first. Stuck mid-design? Fermi's AI tutor notices where you are stuck and decides whether to explain, ask or show.
Next step: design a PDA for balanced brackets and trace (()) and ()) by hand.



