Chapter 5

Pushdown automata

A stack supports nested matching and unbounded counts. It does not provide arbitrary access to saved symbols. Read the transition convention and acceptance convention before tracing a PDA.

5.1 Stack transitions and acceptance

Past papers · CS 2014–2026 (23 papers): 4 questions, 8 marks

An NPDA is M=(Q,Σ,Γ,δ,q0,Z0,F)M=(Q,\Sigma,\Gamma,\delta,q_0,Z_0,F), where Γ\Gamma is the stack alphabet and Z0Z_0 the initial stack symbol. A transition may consume an input symbol or ϵ\epsilon, inspect and pop the top symbol, replace it by a finite string and change state.

Acceptance conventionRequired final configuration after all input is read
Final state(q,ϵ,γ)(q,\epsilon,\gamma) with q∈Fq\in F; stack unrestricted
Empty stack(q,ϵ,ϵ)(q,\epsilon,\epsilon); state unrestricted
BothFinal state and empty stack simultaneously

For NPDAs these conventions describe the same class of languages, with a suitable machine conversion. They are not interchangeable for one unchanged machine. Add a fresh bottom marker and a drain state to convert final-state acceptance to empty-stack acceptance; permit draining only after an old final state has been reached. An early drain cannot accept unread input.

5.2 CFG and PDA equivalence

To simulate a CFG, put its start variable on the stack. Nondeterministically replace a top variable AA by a right-hand side of AA; match a top terminal against the next input symbol and pop it. With our leftmost-top notation, write the right-hand side in its ordinary order. In an implementation that pushes symbols one at a time, push it from right to left. Accept by empty stack after consuming the input.

For the reverse construction, use a variable [pXq][pXq] to represent all strings that take the PDA from state pp with XX on top to state qq just after removing XX, preserving the stack underneath. If a transition replaces XX by YZYZ, guess the intermediate state after removing YY, then remove ZZ. A normalised PDA with pushes of at most two symbols makes this construction finite and direct.

5.3 Determinism and marked matching

Past papers · CS 2014–2026 (23 papers): 3 questions, 4 marks

A DPDA has at most one enabled move for a state, next input and stack top. In addition, if an ϵ\epsilon move is available for a state and stack top, no consuming move is allowed for that same pair. A machine cannot “choose whether” to use an empty move.

With final-state acceptance, DPDAs recognise the deterministic context-free languages (DCFLs). Every regular language is a DCFL: ignore the stack. Every DCFL is an unambiguous CFL, but some unambiguous CFLs are not deterministic.

Language, indices nonnegative unless statedClassification and reason
{anbn}\{a^nb^n\}DCFL, nonregular; the first bb determines the phase change
{wcwR:w∈{a,b}∗}\{wcw^R:w\in\{a,b\}^*\}, cc a new symbolDCFL; the marker locates the middle
{wwR:w∈{a,b}∗}\{ww^R:w\in\{a,b\}^*\}CFL, not DCFL; the middle is unmarked
a∗∪{anbn}a^*\cup\{a^nb^n\}DCFL; final states can accept during the all-aa phase, then require complete matching after a bb
{ambn:m≠n}\{a^mb^n:m\ne n\}DCFL; underflow or leftover count detects inequality

DCFLs are closed under complement, intersection with a regular language, and union with a regular language. They are not closed under unrestricted union, intersection, concatenation, star or reversal. Complementation requires a proper terminating/completed deterministic construction; merely switching final states may fail when there are missing moves or infinite ϵ\epsilon computations.

Last-minute recall

  • Acceptance always consumes all input.
  • Specify which end of a written stack is the top.
  • NPDA final-state and empty-stack conventions are equivalent by conversion.
  • A DPDA cannot have competing empty and consuming moves.
  • A middle marker can turn nondeterministic matching into deterministic matching.
  • Every DCFL is unambiguous; the converse fails.
  • Deterministic empty-stack and final-state acceptance need different treatment.

Revise offline: the whole Theory of Computation handbook as one PDF

40 pages · 1.7 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections