← back to Theory of Computation

Pushdown Automata

Maheshwari & Smid · Ch. 5 · Introduction to Theory of Computation

A pushdown automaton (PDA) is a finite automaton equipped with a stack. The stack gives it memory to count, match, and nest. PDAs recognize exactly the context-free languages.

Definition

A PDA is a 6-tuple (Q, Σ, Γ, δ, q0, F):

Each transition reads an input symbol (or ε), pops from the stack (or not), moves to a new state, and pushes to the stack (or not).

q0 q1 q2 q0 (self-loop) --> a, ε → A q1 --> ε, ε → ε q1 (self-loop) --> b, A → ε q2 --> ε, $ → ε A A $ stack

Simulating a PDA

Scheme
Python

PDAs = CFGs

Every CFG can be converted to an equivalent PDA, and every PDA can be converted to a CFG. The context-free languages are exactly those recognized by pushdown automata.

Pumping lemma for context-free languages

Similar to the regular pumping lemma, but with two pumpable sections. If L is context-free, then for sufficiently long strings s in L, you can write s = uvxyz where v and y can be pumped together. This proves that some languages (like anbncn) are not context-free.

Scheme
Python
Neighbors
  • 🪄 SICP Ch.8 — the call stack is a pushdown automaton: function calls push frames, returns pop them
  • 💻 OS Ch.2 — process stacks and call stack management implement PDA mechanics
  • 🐱 Category Theory Ch.19 — algebraic data types model recursive structures recognized by PDAs