Introduction
A deterministic pushdown automaton (DPDA) never has a choice of move: at most one transition applies for the current state, input symbol (or ), and top-of-stack symbol, and -input moves cannot compete with a defined symbol move. Languages of DPDAs are deterministic context-free languages (DCFLs). Every DCFL is a CFL, but not conversely. Parsers for programming languages rely on deterministic stack discipline (LR parsing).
Prerequisites
- Pushdown Automata: general PDAs and acceptance modes.
Core concepts
Determinism conditions
For every , , :
- and ;
- if , then for every .
So the machine has at most one legal action in every configuration. Condition 2 is the one that is easy to overlook: an -move and a symbol move on the same state and top symbol already make the PDA nondeterministic, even though each set has size 1.
Acceptance
DCFLs are usually defined via acceptance by final state. Acceptance by empty stack defines a strictly smaller family: a language is accepted by empty stack by some DPDA iff it is a DCFL with the prefix property (no string in the language is a proper prefix of another). Even the regular language fails it (a is a prefix of aa), so it has a DPDA by final state but none by empty stack.
The end-marker trick. For any , the language (with a fresh symbol ) has the prefix property, because every string ends at its only . And is a DCFL iff is a DCFL. So "DCFL by final state" and "empty-stack DPDA for " describe the same family, and parsers add an end marker to the input for exactly this reason.
DCFL versus CFL
Proper inclusions:
Witnesses:
- is DCFL (deterministic push on , pop on ).
- over is CFL but not DCFL.
- is CFL (nondeterministic choice) but not DCFL.
Closure properties (contrast)
| Operation | DCFL | CFL | Counterexample or reason for DCFL |
|---|---|---|---|
| Complement | yes | no | run is unique; complete the DPDA, remove -loops, swap accepting conditions |
| Intersection with a regular language | yes | yes | product of the DPDA with a DFA |
| Inverse homomorphism | yes | yes | simulate on the DPDA |
| Union | no | yes | |
| Intersection | no | no | , not even a CFL |
| Concatenation, star | no | yes | the guessed cut point plays the role of the guessed middle |
| Reversal | no | yes | is a DCFL (the first symbol decides), its reversal is not (the deciding symbol comes last) |
| Homomorphism | no | yes | erase the deciding symbol: maps the DCFL above to , which is not a DCFL |
| Union with a regular language, difference with a regular language | yes | yes | complement plus intersection with a regular language |
DCFLs are closed under complement but not union; CFLs are closed under union but not complement. A consequence: since DCFLs are closed under complement, a CFL whose complement is not a CFL cannot be a DCFL. For example is a CFL and its complement is not, so is not a DCFL.
How it works
Designing a DPDA for
No guessing: while reading , push; on first , start popping; never return to pushing. Accept by final state when stack returns to bottom after the last . Test that the stack has returned to its bottom and accept by final state only after the entire input is consumed; an explicit endmarker is an alternative convention.
Why or fails deterministically
A DPDA reading 's then 's must decide whether to match 's against 's or save the 's to match 's. Looking ahead cannot resolve both futures for all strings. Formal proofs use the DCFL pumping properties or known theorems; for classification, the witness language and this intuition are what you apply.
Algorithms and pseudocode
Simulation of a DPDA is deterministic:
Input positions are 0-based; i is the number of symbols already consumed.
DPDA-RUN(P, w)
1 q <- q0; stack <- [Z0]; i <- 0
2 acc <- false
3 while true
4 if i == |w| and q in F: acc <- true
5 if an eps-move on (q, top) is defined: apply it
6 else if i < |w| and a move on (q, w[i], top) is defined:
7 apply it; i <- i+1
8 else break
9 return accLine 4 implements acceptance by final state: is accepted if any configuration reached after the whole input is read has an accepting state, including states passed during the trailing -moves. The last state alone is not the test. For example, take and with . On input a the run is : it passes through accepting after reading all of a, so a is accepted although the run ends in . On the run stays in and rejects; on aa it is stuck in with input left and rejects.
The simulator here supports machines with no infinite -move sequence; this is an input restriction, not a condition in the formal definition of a DPDA. For a fixed machine whose -bursts are uniformly bounded, the simulation time is . Merely excluding repeated finite control states without accounting for the stack does not prove such a bound.
Mathematical explanation
Prefix property for empty-stack DPDAs
If and both empty the stack at their ends, the machine after already has empty stack and cannot read . Hence no DCFL accepted by empty stack can contain both and for .
Relationship to LR grammars
Deterministic context-free languages are exactly the languages generated by LR() grammars, and already suffices for every DCFL. That theorem justifies why shift-reduce parsers can be built for typical programming languages. It also gives: every DCFL has an unambiguous grammar, so an inherently ambiguous language is never a DCFL. The converse fails: the even palindromes have the unambiguous grammar but are not a DCFL.
Decision problems for DPDAs
| Question | DPDA (DCFL) | general PDA or CFG |
|---|---|---|
| membership | decidable, linear time | decidable, by CYK |
| emptiness, finiteness | decidable | decidable |
| decidable (complement, then emptiness) | undecidable | |
| decidable (a deep theorem by Senizergues) | undecidable | |
| undecidable | undecidable | |
| is regular | decidable | undecidable |
| is a DCFL, for a CFG | not applicable | undecidable |
The intersection-emptiness row is the exception to note: two DCFLs can encode Post's correspondence problem, so even for DPDAs disjointness is undecidable.
Worked examples
Example 1: is DCFL
DPDA as above. Sample: aabb accepts; aab rejects; aaabbb accepts.
Example 2: union of two DCFLs that is not a DCFL
and are both DCFLs (push one or two symbols per ). Their union is a CFL (guess which branch) but not a DCFL. Proof idea: suppose a DPDA accepts . Because is deterministic, its unique run on passes through the accepting configuration it reaches after . Build a PDA that runs and, from any accepting state reached after some s, may switch to a copy of in which every is renamed . It accepts () iff accepts , that is iff . So would be context-free, which is false. Note that is a DCFL: the first (or the end of input) decides, so not every union fails.
Example 3: regular languages are DCFL
Every regular language has a DFA; a DFA is a DPDA that ignores the stack. So .
Example 4: palindromes
Even-length palindromes over a 2-letter alphabet: CFL via nondeterministic midpoint guess; not DCFL.
Example 5: complement intuition
Because a DPDA's run is unique, one can flip acceptance conditions to accept the complement, after two repairs: add a dead state so the machine never gets stuck before the input ends, and remove -loops so it never runs forever. A further subtlety is that one input string can pass through several states during -moves after its last symbol; the complement must accept iff none of those states is accepting. Nondeterministic PDAs cannot do this in general (CFLs are not closed under complement).
Example 6: is it a DCFL?
| Language | DCFL? | Reason |
|---|---|---|
| yes | the marker c tells the machine when to start popping | |
| no | the middle must be guessed | |
| yes | push s, pop on s, accept unless the counts end equal; complement of a DCFL within | |
| yes | the first non- symbol decides which check to run | |
| no | Example 2 | |
| yes | surplus counter, deterministic | |
| no | not even a CFL |
Important properties and observations
- DPDA PDA in language power.
- DCFLs closed under complement; not under union/intersection.
- CFLs closed under union; not under complement/intersection.
- Empty-stack DPDA languages are prefix-free.
DPDA versus NPDA. Same hardware, different transition restraint; languages differ.
Common misconceptions.
- "All CFLs have DPDAs." False.
- "DCFLs are closed under union like regular languages." False.
- "Accept by empty stack equals accept by final state for DPDAs." False in general.
GATE examination perspective
- CLASSIFY THE WITNESS. Know one CFL-not-DCFL example.
- CLOSURE TABLE. Memorize DCFL vs CFL vs regular closure contrasts.
- PARSING LINK. LR parsers need deterministic stack languages.
- NO GUESSING. If your design says "guess the middle", it is not a DPDA.
- MARKER DECIDES. A separator or a first symbol that announces the branch keeps the language deterministic; a decision that depends on the future does not.
- PREFIX PROPERTY. "DPDA by empty stack" languages are exactly the prefix-free DCFLs; and need final-state acceptance.
- END MARKER. is a DCFL iff is, and is always prefix-free.
- DECIDABILITY CONTRAST. DPDA equivalence and universality are decidable; for CFGs they are not. Disjointness is undecidable for both.
- UNAMBIGUOUS IS NOT DETERMINISTIC. Every DCFL is unambiguous, not conversely.
Summary
Sources
- M. Sipser, Introduction to the Theory of Computation, 3rd ed., Cengage Learning: Section 2.4 (deterministic context-free languages: properties of DCFLs, deterministic context-free grammars, relationship of DPDAs and DCFGs, parsing and LR(k) grammars).
- J. E. Hopcroft, R. Motwani, J. D. Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Pearson Addison-Wesley: Section 6.4 (definition of a DPDA, regular languages and DPDAs, DPDAs and CFLs, DPDAs and ambiguous grammars).
- P. Linz, An Introduction to Formal Languages and Automata, 6th ed., Jones & Bartlett Learning: Sections 7.3 (deterministic pushdown automata and deterministic context-free languages) and 7.4 (grammars for deterministic context-free languages).