Introduction

A deterministic pushdown automaton (DPDA) never has a choice of move: at most one transition applies for the current state, input symbol (or ε\varepsilon), and top-of-stack symbol, and ε\varepsilon-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

Core concepts

Determinism conditions

For every q∈Qq \in Q, a∈Σa \in \Sigma, X∈ΓX \in \Gamma:

  1. ∣δ(q,a,X)∣≤1|\delta(q,a,X)| \le 1 and ∣δ(q,ε,X)∣≤1|\delta(q,\varepsilon,X)| \le 1;
  2. if δ(q,ε,X)≠∅\delta(q,\varepsilon,X) \ne \emptyset, then δ(q,b,X)=∅\delta(q,b,X) = \emptyset for every b∈Σb \in \Sigma.

So the machine has at most one legal action in every configuration. Condition 2 is the one that is easy to overlook: an ε\varepsilon-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 a∗a^* 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 LL, the language L$={w$∣w∈L}L\text{\textdollar} = \{ w\text{\textdollar} \mid w \in L \} (with a fresh symbol $\text{\textdollar}) has the prefix property, because every string ends at its only $\text{\textdollar}. And LL is a DCFL iff L$L\text{\textdollar} is a DCFL. So "DCFL by final state" and "empty-stack DPDA for L$L\text{\textdollar}" describe the same family, and parsers add an end marker to the input for exactly this reason.

DCFL versus CFL

Proper inclusions:

Regular⊊DCFL⊊CFL.\mathrm{Regular} \subsetneq \mathrm{DCFL} \subsetneq \mathrm{CFL}.

Witnesses:

  • {anbn}\{a^n b^n\} is DCFL (deterministic push on aa, pop on bb).
  • {wwR}\{ ww^R \} over {0,1}\{0,1\} is CFL but not DCFL.
  • {aibjck∣i=j or j=k}\{a^i b^j c^k \mid i=j \text{ or } j=k\} is CFL (nondeterministic choice) but not DCFL.

Closure properties (contrast)

OperationDCFLCFLCounterexample or reason for DCFL
Complementyesnorun is unique; complete the DPDA, remove ε\varepsilon-loops, swap accepting conditions
Intersection with a regular languageyesyesproduct of the DPDA with a DFA
Inverse homomorphismyesyessimulate h(a)h(a) on the DPDA
Unionnoyes{aibjck∣i=j}∪{aibjck∣j=k}\{a^i b^j c^k \mid i = j\} \cup \{a^i b^j c^k \mid j = k\}
Intersectionnono{anbncm}∩{ambncn}={anbncn}\{a^n b^n c^m\} \cap \{a^m b^n c^n\} = \{a^n b^n c^n\}, not even a CFL
Concatenation, starnoyesthe guessed cut point plays the role of the guessed middle
Reversalnoyes{c anbn}∪{d anb2n}\{c\,a^n b^n\} \cup \{d\,a^n b^{2n}\} is a DCFL (the first symbol decides), its reversal {bnanc}∪{b2nand}\{b^n a^n c\} \cup \{b^{2n} a^n d\} is not (the deciding symbol comes last)
Homomorphismnoyeserase the deciding symbol: h(c)=h(d)=εh(c) = h(d) = \varepsilon maps the DCFL above to {anbn}∪{anb2n}\{a^n b^n\} \cup \{a^n b^{2n}\}, which is not a DCFL
Union with a regular language, difference with a regular languageyesyescomplement 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 {ww}‾\overline{\{ww\}} is a CFL and its complement {ww}\{ww\} is not, so {ww}‾\overline{\{ww\}} is not a DCFL.

How it works

Designing a DPDA for anbna^n b^n

No guessing: while reading aa, push; on first bb, start popping; never return to pushing. Accept by final state when stack returns to bottom after the last bb. 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 i=ji=j or j=kj=k fails deterministically

A DPDA reading aa's then bb's must decide whether to match aa's against bb's or save the bb's to match cc'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.

Text
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 acc

Line 4 implements acceptance by final state: ww is accepted if any configuration reached after the whole input is read has an accepting state, including states passed during the trailing ε\varepsilon-moves. The last state alone is not the test. For example, take δ(q0,a,Z0)=(q1,Z0)\delta(q_0, a, Z_0) = (q_1, Z_0) and δ(q1,ε,Z0)=(q2,Z0)\delta(q_1, \varepsilon, Z_0) = (q_2, Z_0) with F={q1}F = \{q_1\}. On input a the run is q0,q1,q2q_0, q_1, q_2: it passes through accepting q1q_1 after reading all of a, so a is accepted although the run ends in q2∉Fq_2 \notin F. On ε\varepsilon the run stays in q0q_0 and rejects; on aa it is stuck in q2q_2 with input left and rejects.

The simulator here supports machines with no infinite ε\varepsilon-move sequence; this is an input restriction, not a condition in the formal definition of a DPDA. For a fixed machine whose ε\varepsilon-bursts are uniformly bounded, the simulation time is O(1+∣w∣)O(1+|w|). 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 xx and xyxy both empty the stack at their ends, the machine after xx already has empty stack and cannot read yy. Hence no DCFL accepted by empty stack can contain both xx and xyxy for y≠εy\neq\varepsilon.

Relationship to LR grammars

Deterministic context-free languages are exactly the languages generated by LR(kk) grammars, and k=1k = 1 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 S→aSa∣bSb∣εS \to aSa \mid bSb \mid \varepsilon but are not a DCFL.

Decision problems for DPDAs

QuestionDPDA (DCFL)general PDA or CFG
membershipdecidable, linear timedecidable, O(n3)O(n^3) by CYK
emptiness, finitenessdecidabledecidable
L=Σ∗L = \Sigma^*decidable (complement, then emptiness)undecidable
L1=L2L_1 = L_2decidable (a deep theorem by Senizergues)undecidable
L1∩L2=∅L_1 \cap L_2 = \emptysetundecidableundecidable
is LL regulardecidableundecidable
is L(G)L(G) a DCFL, for a CFG GGnot applicableundecidable

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: anbna^n b^n is DCFL

DPDA as above. Sample: aabb accepts; aab rejects; aaabbb accepts.

Example 2: union of two DCFLs that is not a DCFL

L1={anbn∣n≥0}L_1 = \{a^n b^n \mid n \ge 0\} and L2={anb2n∣n≥0}L_2 = \{a^n b^{2n} \mid n \ge 0\} are both DCFLs (push one or two symbols per aa). Their union LL is a CFL (guess which branch) but not a DCFL. Proof idea: suppose a DPDA MM accepts LL. Because MM is deterministic, its unique run on anb2na^n b^{2n} passes through the accepting configuration it reaches after anbna^n b^n. Build a PDA that runs MM and, from any accepting state reached after some bbs, may switch to a copy of MM in which every bb is renamed cc. It accepts anbncka^n b^n c^k (k≥1k \ge 1) iff MM accepts anbn+ka^n b^{n+k}, that is iff k=nk = n. So {anbncn∣n≥1}\{a^n b^n c^n \mid n \ge 1\} would be context-free, which is false. Note that {a}∪{anbn∣n≥1}\{a\} \cup \{a^n b^n \mid n \ge 1\} is a DCFL: the first bb (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 Regular⊆DCFL\mathrm{Regular} \subseteq \mathrm{DCFL}.

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 ε\varepsilon-loops so it never runs forever. A further subtlety is that one input string can pass through several states during ε\varepsilon-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?

LanguageDCFL?Reason
{wcwR∣w∈{a,b}∗}\{w c w^R \mid w \in \{a,b\}^*\}yesthe marker c tells the machine when to start popping
{wwR∣w∈{a,b}∗}\{w w^R \mid w \in \{a,b\}^*\}nothe middle must be guessed
{anbm∣n≠m}\{a^n b^m \mid n \ne m\}yespush aas, pop on bbs, accept unless the counts end equal; complement of a DCFL within a∗b∗a^* b^*
{anbn∣n≥0}∪{ancn∣n≥0}\{a^n b^n \mid n \ge 0\} \cup \{a^n c^n \mid n \ge 0\}yesthe first non-aa symbol decides which check to run
{anbn}∪{anb2n}\{a^n b^n\} \cup \{a^n b^{2n}\}noExample 2
{w∣#a(w)=#b(w)}\{w \mid \#_a(w) = \#_b(w)\}yessurplus counter, deterministic
{anbncn}\{a^n b^n c^n\}nonot even a CFL

Important properties and observations

  • DPDA ⊊\subsetneq 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; a∗a^* and {anbn}\{a^n b^n\} need final-state acceptance.
  • END MARKER. LL is a DCFL iff L$L\text{\textdollar} is, and L$L\text{\textdollar} 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

  1. 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).
  2. 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).
  3. 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).

Next steps