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 where:
- — finite set of states.
- — input alphabet (symbols read from the input).
- — stack alphabet (symbols stored on the stack; need not equal ). The marker \text{\}$ is conventionally pushed first to mark the bottom of the stack.
- — the transition function. Given a state, an input symbol (or ), and a popped stack symbol (or ), it returns a set of (next state, pushed symbol) pairs. The power set encodes nondeterminism — one configuration may lead to several choices. Here and .
- — start state.
- — set of accept states (multiple allowed).
Acceptance. A PDA accepts (each ) if there exist a sequence of states and a sequence of stack contents such that:
- and — start in the start state with an empty stack.
- For each , the move is legal: writing and (with and ), we require — i.e. pop , push , leaving the rest untouched.
- — 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.
- — push a for each input , nondeterministically guess the midpoint, then pop a for each input ; pop \text{\}$ to accept.
- (a string followed by its reverse) — push each input symbol on the first half, guess the midpoint, then require each next symbol to match (pop) the top of the stack.
- Complements such as the complement of — handled by splitting odd-length strings into a stack-free path and forcing at least one mismatch on the even path.
- — count the 's on the stack, then nondeterministically choose to match them against the 's or against the 's.
Two stacks = a Turing machine. A single stack cannot recognize . 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.
- Push S\text{\}$ (start variable over bottom marker).
- For each grammar rule , add -moves that pop and push the symbols of (in reverse, so the leftmost ends up on top).
- For each terminal , add a move that reads and pops .
- When only \text{\}$ remains, pop it and accept.
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 (two variables) or (one terminal); only the start variable may derive , and nothing derives the start variable. In CNF the binary-branching parse tree forces a height bound: a string of length has a parse tree of height at least 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 must repeat. The subtree at the higher occurrence can be replaced by the subtree at the lower (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 is context-free, there is a pumping length such that every with can be written with:
- (the pumped parts are nonempty),
- (the pumped region is bounded),
- for every .
The constant is where is the number of variables. A string of length forces a parse tree of height , hence a repeated variable, hence a split that can be pumped. The bound comes from the lowest repeating variable: the subtree below has height , so it yields at most symbols.
Using it to prove non-context-freeness (contrapositive). A language is not context-free if: for every , there is a string with such that for every split with and , there is some with . This is the tool used (next time) to show 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 has a parse tree whose height satisfies . With variables, set the pumping length ; any string of length then forces , so a variable repeats along some root-to-leaf path.
Take a grammar with variables (so ) and a string of length :
Because a variable repeats, label the lower occurrence and the higher and split the string as , where descend from the root but not from ; descend from but not from ; and descends from . CNF guarantees contributes a symbol outside 's subtree, so ; and the subtree under has height , so . Replacing 's subtree by 's repeatedly (or collapsing it) pumps the string:
where corresponds to collapsing down to (deleting one copy of and ).
Summary
- A PDA is the 6-tuple : an NFA plus a stack, with nondeterministic transitions valued in .
- Acceptance requires a run from with an empty stack to an accept state, each step popping/pushing consistently with .
- PDAs and context-free grammars are equivalent; the grammar-to-PDA construction keeps the sentential form on the stack (push S\text{\}\varepsilon\text{$}$ to accept).
- A single stack cannot recognize ; two stacks already give full Turing-machine power.
- In Chomsky normal form, a length- string forces parse-tree height , so a string of length forces a repeated variable.
- The CFL pumping lemma ( with , , ) and its contrapositive are the standard tools for proving a language is not context-free.