4.6.11 · D5Theory of Computation
Question bank — Equivalence of CFGs and PDAs
Before you start, refresh the vocabulary, the two acceptance modes, and the two constructions we lean on everywhere below. Nothing on this page uses a symbol we have not first pinned down here.
See Pushdown Automata, Context-Free Grammars, and Leftmost Derivations and Parse Trees for fuller treatments; everything needed below is recapped right here.
With these boxes in hand, every trap below is self-contained.
True or false — justify
A CFG and a PDA can describe exactly the same class of languages.
True. This is the theorem itself: is context-free some PDA accepts ; the shared engine is a single stack that mirrors grammar recursion.
The equivalence holds even for deterministic PDAs, since determinism is just a special case.
False. The CFG↔PDA equivalence needs nondeterministic PDAs; deterministic PDAs (Deterministic PDAs and DCFLs) recognize only a proper subset (the DCFLs), e.g. they cannot accept .
Acceptance by final state and acceptance by empty stack recognize different language classes.
False. They recognize the same class: from an empty-stack PDA you build a final-state one by pushing a private bottom marker and entering an accept state only when it resurfaces, and vice-versa. So we freely pick whichever mode is convenient.
A PDA with two stacks is still limited to context-free languages.
False. Two stacks let the machine simulate a Turing machine (one stack = tape left of the head, one = right), so it escapes the context-free class entirely. Exactly one stack is what makes the equivalence hold.
In the CFG→PDA construction, the PDA needs many control states to track which rule it is applying.
False. A single state suffices (see Construction A), because a grammar has no "control state" — all live information sits in the sentential form, which the PDA stores entirely on its stack.
The invariant "(input read) (stack) = current sentential form" (where is concatenation) holds only at acceptance.
False. It holds at every step of the simulation; that is precisely why it proves correctness — acceptance is just the special moment when the stack is empty and all input is read.
(from Construction B) stands for "there exists some path from state to state ".
False. It means a path that reads some and nets to zero stack change (balanced, never dipping below start height). Plain reachability ignores the stack and would over-generate.
Since came back out of the PDA→CFG trick, the two constructions are literally inverse functions.
False. They are inverse in spirit, not as functions — running CFG→PDA→CFG need not return a syntactically identical grammar, only an equivalent one generating the same language.
The rule is optional decoration.
False. It is the base case: staying at the same state reading nothing with no net stack change is a genuine balanced run, and without it recursion never terminates and no string is generated.
Every context-free language is accepted by some PDA whose input is always consumed one symbol per move.
False. The CFG→PDA machine uses -moves (consuming no input) whenever it expands a variable; only terminal-matching moves consume input.
A worked trace to anchor the ideas
Spot the error
"In CFG→PDA, when we expand a variable using rule , the PDA also reads an input symbol during that expansion."
Error: expansion is an -move — it consumes no input. Input is consumed only later, when the terminal sits on top of the stack and is matched against the next input symbol.
"To match a terminal on the stack, the PDA pushes and moves on."
Error: matching pops and pushes nothing (). The terminal was a promise already on the stack; matching fulfills it by removing it, not by adding more.
"Rule works for one specific well-chosen ."
Error: the grammar adds this split rule for all intermediate states , and the derivation picks the right one. The split can happen at any mid-run moment the stack returns to its start height.
"In the match rule , the pushed symbol and the popped symbol may differ."
Error: recall from Construction B that the pushed stack symbol (pushed when leaving on toward ) must be the same popped when entering on from — it is the bottom bracket. Mismatched symbols do not correspond to any valid balanced run.
"We only need the split rule OR the match rule, since one subsumes the other."
Error: both are required and they are exhaustive together — the first pushed symbol is popped either at the very end (match rule) or strictly earlier (split rule). Drop either and you miss half of all balanced runs.
"Determinizing the CFG→PDA construction just removes redundant guesses without losing languages."
Error: the guessing (which rule to expand) is essential. Forcing determinism restricts you to DCFLs, a strict subset — e.g. over needs nondeterminism.
"To run PDA→CFG we can skip normalizing the PDA and read off triple-rules directly."
Error: the triple trick requires the normal form where every move pushes exactly one symbol or pops exactly one (no pure replacements, no zero-change moves) and acceptance is by empty stack. Without it, the "one push, one matching pop" bracket structure isn't guaranteed.
Why questions
Why does a stack (rather than a counter or a queue) capture context-free languages?
Because grammar derivations are nested — a variable expands inside another expansion — and nesting is exactly last-in-first-out bracket structure, which is what a stack stores. A queue (FIFO) would break the nesting order.
Why store the "unmatched suffix of the sentential form" on the stack instead of the whole string?
Because the prefix already matched against input is done and gone; only the part we still "owe" (terminals still to match, variables still to expand) needs recording, and that suffix behaves exactly like a stack under leftmost derivation.
Why does the PDA→CFG variable definition insist the stack never dips below its starting height?
If it dipped below, the run would be popping symbols that belong to an outer bracket — that outer structure would be handled by a different (enclosing) variable. Staying at-or-above keeps each variable responsible for one balanced layer.
Why is the CFG→PDA machine single-state but the PDA→CFG grammar has many variables ?
The grammar side must encode the PDA's states, and it does so inside variable subscripts () rather than in a control unit. The single-state PDA had nothing to encode, so the asymmetry is just where the state information lives.
Why does simulating a leftmost derivation (not any derivation) make the stack simulation clean?
Leftmost derivation always expands the leftmost variable, matching the fact that a stack always exposes its top. Any-order derivation would need access to variables buried in the middle, which a stack forbids. See Leftmost Derivations and Parse Trees.
Why can we use empty-stack acceptance for the PDA→CFG direction without loss of generality?
Because empty-stack and final-state acceptance are equivalent for PDAs, and empty-stack directly encodes "the whole balanced run finished," which is exactly the semantics the grammar needs.
Edge cases
What does the CFG→PDA machine do with the empty string when (e.g. rule )?
It applies the -expansion , popping with no input read, leaving the stack empty and accepting — so is handled by an expansion move, not a match move.
If the grammar has a rule , does the PDA read any input for it?
No. It pops and pushes the empty string, consuming no input — an -move like every expansion, correct because applying a rule never consumes input.
What happens in CFG→PDA if the top of the stack is a terminal but the next input symbol is ?
That particular nondeterministic path dies (no matching move). Acceptance requires some path to succeed, so a wrong guess simply prunes itself and other paths continue.
What is when and ?
It is the base case : going nowhere reads the empty string with zero net stack change — the smallest balanced run.
Does the equivalence still hold for a finite language (no recursion at all)?
Yes. A finite language is trivially context-free, and its PDA simply never needs to reuse the stack recursively — the theorem covers this as a degenerate case where the recursion depth is bounded.
If the PDA never touches its stack (acts like a finite automaton), is the resulting language still context-free?
Yes — every regular language is context-free (regular context-free). The stack is available but unused, giving a balanced-but-trivial run for every accepted string.
Can a single string have two accepting runs in the CFG→PDA machine?
Yes, if the grammar is ambiguous the string has multiple leftmost derivations, each giving a distinct accepting path. Nondeterminism accepts as long as at least one succeeds, so ambiguity is harmless for recognition. See Leftmost Derivations and Parse Trees.
What if the PDA can empty its stack in the middle of reading input and then push again — does one cover that?
No single match-rule variable covers it; that mid-run return to start height triggers the split rule , factoring the run into two consecutive balanced pieces.
Why must PDA→CFG normalisation eliminate "pure replacement" (zero net stack change) moves before we start?
Because such a move changes neither height nor bracket structure, so it fits neither the push nor the pop half of the match rule; we rewrite each into a push-then-pop pair so every move is cleanly a single push or single pop and the triple grammar can capture it.
Do -loops in the PDA (an infinite cycle of -moves that never touches input or net stack height) break the PDA→CFG construction?
No — they only add derivations for (or re-derive the same ), never a new string, so is unchanged. The grammar stays finite because it enumerates state-pairs , not individual runs, so a cycle contributes at most a -style self-reference rather than infinitely many rules.
Recall One-line self-test
- What does mean? ::: In state , optionally reading and popping stack-top , the PDA may go to and push .
- What makes two stacks too powerful? ::: They simulate a Turing machine, leaving the context-free class.
- Where does the PDA→CFG grammar store PDA states? ::: In the subscripts of each variable .
- When is input consumed in CFG→PDA? ::: Only during a terminal match, never during expansion.
- The two exhaustive PDA→CFG cases? ::: First pushed symbol popped at the very end (match) or earlier (split).
- Why normalise the PDA first? ::: So every move is a single push or single pop, matching the triple grammar's bracket structure.