The Timpson Lyceum seal

The Timpson Lyceum · Computation Theory

Lecture 10 (Computation Theory) Pushdown Automata, Non-Context-Free Languages, and Pumping Lemma 2.0

Pushdown Automata, Non-Context-Free Languages, and Pumping Lemma 2.0 – Lecture 10

Overview

This lecture completes the theory of pushdown automata (PDAs) and pivots to proving that some languages are not context-free. We pin down the formal six-tuple definition of a PDA and the precise acceptance condition, then build several example machines and write one out as an explicit transition table. We state (and sketch one direction of) the equivalence between PDAs and context-free grammars: a language is context-free if and only if some PDA recognizes it. Finally, we develop the pumping lemma for context-free languages, reasoning about parse-tree height in Chomsky normal form rather than about a machine's states. This pumping lemma is the central tool for proving a language has no context-free grammar.

Key Concepts

Pushdown automaton (PDA). A PDA is like a nondeterministic finite automaton augmented with a stack. On each transition it may read an input symbol, pop a symbol off the top of the stack, and push a string of symbols onto the stack — any of these "may" be the empty string. The stack gives the machine unbounded memory (organized last-in-first-out), which is exactly the extra power that lets it recognize context-free languages.

Formal definition. A PDA is a 6-tuple (Q,Σ,Γ,δ,q0,F)(Q, \Sigma, \Gamma, \delta, q_0, F) where:

Acceptance. A PDA accepts w=w1w2⋯wmw = w_1 w_2 \cdots w_m (each wi∈Σεw_i \in \Sigma_\varepsilon) if there exist a sequence of states r0,r1,…,rmr_0, r_1, \ldots, r_m and a sequence of stack contents s0,s1,…,sm∈Γ∗s_0, s_1, \ldots, s_m \in \Gamma^* such that:

  1. r0=q0r_0 = q_0 and s0=εs_0 = \varepsilon — start in the start state with an empty stack.
  2. For each ii, the move is legal: writing si=ats_i = a t and si+1=bts_{i+1} = b t (with a,b∈Γεa, b \in \Gamma_\varepsilon and t∈Γ∗t \in \Gamma^*), we require (ri+1,b)∈δ(ri,wi+1,a)(r_{i+1}, b) \in \delta(r_i, w_{i+1}, a) — i.e. pop aa, push bb, leaving the rest tt untouched.
  3. rm∈Fr_m \in F — end in an accept state.

By convention these machines push \text{\}$ first and pop it last so the stack is empty at acceptance, but emptying the stack is a design habit, not a strict requirement of the definition.

Explicit transition tables. A PDA can be written as a table indexed by (current state) × (input symbol) × (popped stack symbol), with each cell holding the set of reachable (state, pushed symbol) pairs. Because the table is genuinely three-dimensional, most cells are the empty set and the layout is awkward — which is why machines are normally drawn as state diagrams instead of tabulated.

Example languages.

Two stacks = a Turing machine. A single stack cannot recognize {ww}\{ww\}. Adding a second stack jumps to full Turing-machine power; beyond two stacks, more stacks add nothing.

Equivalence of PDAs and CFGs. A language is context-free if and only if some PDA recognizes it. The grammar-to-PDA direction is constructive: build a PDA that keeps the current sentential form on its stack.

The reverse direction (PDA-to-grammar) is also true but its proof is long (two nested inductions), so it is taken on faith here.

Chomsky normal form (CNF). Every CFL has a grammar where every rule is A→BCA \to BC (two variables) or A→aA \to a (one terminal); only the start variable may derive ε\varepsilon, and nothing derives the start variable. In CNF the binary-branching parse tree forces a height bound: a string of length nn has a parse tree of height at least h≥⌈log⁡2n⌉+1.h \ge \lceil \log_2 n \rceil + 1. The height also equals the longest chain of variables from root to a terminal.

Repeating variables drive pumping. If a root-to-leaf path is long enough, some variable RR must repeat. The subtree at the higher occurrence R∗R^* can be replaced by the subtree at the lower RR (or vice versa), growing or shrinking the derivation while keeping it valid. This is the context-free analogue of "taking a loop."

Pumping lemma for context-free languages. If AA is context-free, there is a pumping length pp such that every s∈As \in A with ∣s∣≥p|s| \ge p can be written s=uvxyzs = uvxyz with:

  1. ∣vy∣≥1|vy| \ge 1 (the pumped parts are nonempty),
  2. ∣vxy∣≤p|vxy| \le p (the pumped region is bounded),
  3. uvnxynz∈Auv^{n}xy^{n}z \in A for every n≥0n \ge 0.

The constant is p=2∣V∣p = 2^{|V|} where ∣V∣|V| is the number of variables. A string of length ≥p\ge p forces a parse tree of height >∣V∣> |V|, hence a repeated variable, hence a split uvxyzuvxyz that can be pumped. The bound ∣vxy∣≤p|vxy| \le p comes from the lowest repeating variable: the subtree below R∗R^* has height ≤∣V∣+1\le |V| + 1, so it yields at most 2∣V∣=p2^{|V|} = p symbols.

Using it to prove non-context-freeness (contrapositive). A language AA is not context-free if: for every pp, there is a string s∈As \in A with ∣s∣≥p|s| \ge p such that for every split s=uvxyzs = uvxyz with ∣vy∣≥1|vy| \ge 1 and ∣vxy∣≤p|vxy| \le p, there is some nn with uvnxynz∉Auv^{n}xy^{n}z \notin A. This is the tool used (next time) to show {0n1n0n}\{0^n 1^n 0^n\} is not context-free.

Worked Example

Goal. Confirm the pumping length / parse-tree-height relationship that underlies the lemma, and read off a sample pumping decomposition.

For a grammar in Chomsky normal form, a derived string of length nn has a parse tree whose height satisfies h≥⌈log⁡2n⌉+1h \ge \lceil \log_2 n \rceil + 1. With ∣V∣|V| variables, set the pumping length p=2∣V∣p = 2^{|V|}; any string of length ≥p\ge p then forces h>∣V∣h > |V|, so a variable repeats along some root-to-leaf path.

Take a grammar with ∣V∣=3|V| = 3 variables (so p=23=8p = 2^3 = 8) and a string of length n=8n = 8:

h≥⌈log⁡2n⌉+1=⌈log⁡28⌉+1=3+1=44=h>∣V∣=3⇒a variable repeats.\begin{aligned} h &\ge \lceil \log_2 n \rceil + 1 \\ &= \lceil \log_2 8 \rceil + 1 = 3 + 1 = 4 \\ 4 = h &> |V| = 3 \quad\Rightarrow\quad \text{a variable repeats.} \end{aligned}

Because a variable RR repeats, label the lower occurrence RR and the higher R∗R^* and split the string as s=uvxyzs = uvxyz, where u,zu,z descend from the root but not from R∗R^*; v,yv,y descend from R∗R^* but not from RR; and xx descends from RR. CNF guarantees R∗R^* contributes a symbol outside RR's subtree, so ∣vy∣≥1|vy| \ge 1; and the subtree under R∗R^* has height ≤∣V∣+1\le |V|+1, so ∣vxy∣≤2∣V∣=p|vxy| \le 2^{|V|} = p. Replacing RR's subtree by R∗R^*'s repeatedly (or collapsing it) pumps the string:

s=u v x y z⟶  u vn x yn z∈Afor all n≥0,\begin{aligned} s &= u\,v\,x\,y\,z \\ &\longrightarrow\; u\,v^{n}\,x\,y^{n}\,z \in A \quad \text{for all } n \ge 0, \end{aligned}

where n=0n = 0 corresponds to collapsing R∗R^* down to RR (deleting one copy of vv and yy).

Summary