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 , where is the stack alphabet and the initial stack symbol. A transition may consume an input symbol or , inspect and pop the top symbol, replace it by a finite string and change state.
| Acceptance convention | Required final configuration after all input is read |
|---|---|
| Final state | with ; stack unrestricted |
| Empty stack | ; state unrestricted |
| Both | Final 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 by a right-hand side of ; 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 to represent all strings that take the PDA from state with on top to state just after removing , preserving the stack underneath. If a transition replaces by , guess the intermediate state after removing , then remove . 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 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 stated | Classification and reason |
|---|---|
| DCFL, nonregular; the first determines the phase change | |
| , a new symbol | DCFL; the marker locates the middle |
| CFL, not DCFL; the middle is unmarked | |
| DCFL; final states can accept during the all- phase, then require complete matching after a | |
| 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 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.