Mathematics.

formal languages

Pushdown Automata

Theory of Computation45 minDifficulty6 out of 10

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

Definition

A (nondeterministic) pushdown automaton is a 6-tuple, where the transition function now also depends on and updates the stack:

P=(Q,Σ,Γ,δ,q0,F)P = (Q, \Sigma, \Gamma, \delta, q_0, F)
Definition
δ:Q×Σε×ΓεP(Q×Γε)\delta: Q \times \Sigma_\varepsilon \times \Gamma_\varepsilon \to \mathcal{P}(Q \times \Gamma_\varepsilon)

Transition: (state, input symbol or ε, stack-top symbol or ε) → set of (next state, symbol to push or ε)

L(P)={wΣ:P has some computation path on w ending in an accept state}L(P) = \{\, w \in \Sigma^* : P \text{ has some computation path on } w \text{ ending in an accept state} \,\}
Language accepted (acceptance by final state)

Notation

NotationMeaning
Γ\GammaThe stack alphabet (symbols that may be pushed/popped)
Σε\Sigma_\varepsilonInput alphabet plus the empty string ε (transitions may read no input)
δ\deltaNondeterministic transition relation reading/updating state, input, and stack top

Theorems

Theorem 1: PDA-CFG equivalence
A language L is context-free if and only if some pushdown automaton accepts L.\text{A language } L \text{ is context-free if and only if some pushdown automaton accepts } L.
Theorem 2: Nondeterminism strictly helps for PDAs
Unlike finite automata, nondeterministic PDAs are strictly more powerful than deterministic PDAs (deterministic CFLs are a proper subset of CFLs).\text{Unlike finite automata, nondeterministic PDAs are strictly more powerful than deterministic PDAs (deterministic CFLs are a proper subset of CFLs).}

Applications

Compiler parsers (LL and LR parsers) are essentially deterministic pushdown automata that match a program's grammar while building a parse tree.

Worked Examples

  1. Push a marker for every 0 read while in the 'reading 0s' state.

    δ(q0,0,ε)=(q0,X)\delta(q_0, 0, \varepsilon) = (q_0, X)
  2. On seeing the first 1, switch to 'reading 1s' and start popping one marker per 1.

    δ(q0,1,X)=(q1,ε)\delta(q_0, 1, X) = (q_1, \varepsilon)
  3. Accept if the stack is exactly empty when the input ends (all markers matched).

    δ(q1,1,X)=(q1,ε),accept if stack=\delta(q_1, 1, X) = (q_1, \varepsilon), \quad \text{accept if stack} = \emptyset

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

Difficulty 5/10

Why can no finite automaton (without a stack) recognize {0ⁿ1ⁿ : n ≥ 0}?

Difficulty 6/10

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?

Difficulty 6/10

Which single feature, added to a finite automaton, produces a pushdown automaton?

Common Mistakes

Common Mistake

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.

Common Mistake

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

A pushdown automaton is a finite automaton augmented with:
The class of languages recognized by pushdown automata is exactly:
Why does {0ⁿ1ⁿ} require a PDA and not just a finite automaton?

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.

  1. 1957

    Noam Chomsky introduces context-free grammars for describing natural and formal languages

    Noam Chomsky

  2. 1960

    ALGOL 60 is specified using a context-free (Backus-Naur Form) grammar, motivating a machine model for parsing

  3. 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.

References