formal languages
Pushdown Automata
You should know: context free grammars
Overview
A pushdown automaton (PDA) is a finite automaton equipped with a single auxiliary memory device: a stack. That one addition is exactly enough to jump from recognizing the regular languages to recognizing the context-free languages — the class generated by context-free grammars, and the class underlying nearly every programming-language syntax. The stack lets a PDA remember an unbounded amount of information, but only in a very restricted, last-in-first-out way, which is precisely the discipline needed to match nested structures like parentheses, HTML tags, or arithmetic expressions.
Intuition
Imagine a finite automaton that also has a stack of plates beside it: it can push a new plate on top, pop the top plate off, or peek at what's on top, but it can never reach into the middle of the stack. To check that parentheses are balanced, push a marker every time you see '(' and pop one every time you see ')'; the string is balanced exactly when the stack empties out at the very end. That single stack — unbounded in size but rigidly LIFO — is exactly what a finite automaton lacks and exactly what's needed to handle arbitrarily deep nesting.
Formal Definition
A (nondeterministic) pushdown automaton is a 6-tuple, where the transition function now also depends on and updates the stack:
Transition: (state, input symbol or ε, stack-top symbol or ε) → set of (next state, symbol to push or ε)
Notation
| Notation | Meaning |
|---|---|
| The stack alphabet (symbols that may be pushed/popped) | |
| Input alphabet plus the empty string ε (transitions may read no input) | |
| Nondeterministic transition relation reading/updating state, input, and stack top |
Theorems
Applications
Worked Examples
Push a marker for every 0 read while in the 'reading 0s' state.
On seeing the first 1, switch to 'reading 1s' and start popping one marker per 1.
Accept if the stack is exactly empty when the input ends (all markers matched).
Answer: A 2-state PDA: push X for every 0, pop an X for every 1; accept iff the stack empties exactly when input ends.
Practice Problems
Why can no finite automaton (without a stack) recognize {0ⁿ1ⁿ : n ≥ 0}?
A code editor highlights mismatched brackets in ( [ ] ) ] as the user types. What PDA-style structure is running behind the scenes, and where does this string first go wrong?
Which single feature, added to a finite automaton, produces a pushdown automaton?
Common Mistakes
Assuming deterministic and nondeterministic PDAs recognize the same class of languages, as with finite automata.
Unlike DFAs/NFAs, deterministic PDAs are strictly weaker than nondeterministic PDAs — some context-free languages (like even-length palindromes) have no deterministic PDA, only a nondeterministic one.
Thinking a PDA can access any position in its stack.
A PDA can only read/modify the single symbol currently on top of the stack — it has no way to peek deeper without popping through everything above.
Quiz
Historical Background
Pushdown automata were formalized in the late 1950s and early 1960s alongside the development of context-free grammars by Noam Chomsky, as researchers sought machine models matching the generative power of CFGs used to describe programming-language syntax (notably ALGOL 60's BNF specification). The proof that PDAs and context-free grammars are exactly equivalent in expressive power became a cornerstone result of formal language theory.
- 1957
Noam Chomsky introduces context-free grammars for describing natural and formal languages
Noam Chomsky
- 1960
ALGOL 60 is specified using a context-free (Backus-Naur Form) grammar, motivating a machine model for parsing
- 1961
Pushdown automata are formalized (independently by several researchers) and shown equivalent to context-free grammars
Summary
- A PDA is a finite automaton plus a single unbounded LIFO stack.
- PDAs recognize exactly the context-free languages — equivalent in power to context-free grammars.
- Unlike finite automata, nondeterministic PDAs are strictly more powerful than deterministic PDAs.
- Compiler parsers and bracket/tag matchers are real-world stack-based PDAs.
Mathematics