G27
Self-checkedTier 1 9 min readtoc.dpda-vs-npda

Deterministic versus nondeterministic PDA

Deterministic pushdown automata and the deterministic context-free languages: the definition of determinism (no choice, including epsilon-moves), why a DPDA is strictly weaker than a PDA (ww^R, i = j or j = k), acceptance by empty stack versus final state for DPDAs (prefix property), the examples that are deterministic (a^n b^n, w c w^R, equal counts, balanced parentheses), closure properties of DCFLs, and the link to LR parsing.

Why it exists

For finite automata nondeterminism adds no power (subset construction). For pushdown automata it does: some context-free languages need guessing. The languages that a deterministic PDA can accept are the deterministic context-free languages (DCFLs); they are exactly the languages for which a compiler can build a fast left-to-right parser without backtracking. GATE asks: which of these languages is deterministic, is DPDA equal to NPDA, which closure properties DCFLs have.

Prerequisites

You need PDAs, configurations and acceptance by final state or empty stack (PDA).

Precise definitions

A PDA P=(Q,Σ,Γ,δ,q0,Z0,F)P = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F) is deterministic (a DPDA) if in every configuration at most one move is possible. Formally, for all q∈Qq \in Q, X∈ΓX \in \Gamma:

  1. δ(q,a,X)\delta(q, a, X) has at most one element for every a∈Σ∪{ε}a \in \Sigma \cup \{\varepsilon\};
  2. if δ(q,ε,X)≠∅\delta(q, \varepsilon, X) \ne \emptyset then δ(q,a,X)=∅\delta(q, a, X) = \emptyset for every a∈Σa \in \Sigma (an ε\varepsilon-move must not compete with an input move).

A language is a deterministic context-free language (DCFL) if some DPDA accepts it by final state. DPDAs accepting by empty stack accept fewer languages (below), so by convention a DPDA accepts by final state.

A DPDA may have ε\varepsilon-moves (they are not choices as long as they are the only move). Its computation on an input is a single path.

How it works

Deterministic examples

anbna^n b^n (n≥0n \ge 0), the machine of the PDA page: push on aa, pop on bb, an ε\varepsilon-move to the final state only when the bottom marker shows and no input move applies. Its start state is also accepting (for n=0n = 0) so no ε\varepsilon-move competes with the move on aa.

w c wRw\,c\,w^R (a marked palindrome, c∉{a,b}c \notin \{a, b\}): the marker cc tells the machine where the middle is, so no guessing is needed. Push the symbols of ww; on cc switch to popping; match each symbol against the top; accept when the bottom marker is exposed.

A deterministic PDA for w c w^R reading abcba: start

Parser run by a script, not typed

Pushdown automaton, one accepting computation (a shortest one found by breadth-first search over configurations). The stack is on the left with its top first; the unread input is on the right.

    stack (top first) (top at the left)
    Z
    unread input
    abcba
    action start in state q0
    transition table: (state, stack top) and input symbol give new state and the symbols pushed (top first)
    state, topabcε
    q0, aq0,aaq0,baq1,a
    q0, bq0,abq0,bbq1,b
    q0, Zq0,aZq0,bZq1,Z
    q1, aq1,ε
    q1, bq1,ε
    q1, Zq2,Z

    Step 0

    The machine starts in state q0 with the stack Z (only the bottom marker) and the whole input unread. The stack is shown with its top at the left.

    0 / 6
    computed by script: the machine is simulated or the sets are constructed by scripts/toc_lib.py, one step at a time. python3 scripts/gen-toc4-traces.py

    Equal numbers of aa and bb and balanced parentheses: the stack holds the surplus. The first versions in these pages end with an ε\varepsilon-move into an accepting state at any time, which competes with the input moves: nondeterministic. The deterministic versions use a state q0q_0 that means "only the bottom marker is on the stack" and is accepting, and a special symbol DD for the lowest surplus symbol, so popping DD returns to q0q_0. Both languages are DCFLs (the machines were checked on all strings up to length 1010 or 1212).

    Nondeterministic is stronger: no DPDA for wwRww^R

    The set of even palindromes {wwR}\{w w^R\} is context-free but is not a DCFL. Intuition: after reading abbabb the machine must be ready for two different futures: the middle may have been after abab (then the string continues with aa, giving abbaabba) or after abbabb (then it continues with bbabba, giving abbbbaabbbba). With one stack and no way to look ahead, a deterministic machine must commit to one of the two readings after each symbol and the other is lost. (The full proof is a longer argument, quoted as a textbook theorem.) The same is true for {aibjck:i=j or j=k}\{a^i b^j c^k : i = j \text{ or } j = k\} (it needs to guess which comparison to make) and for {anbn}∪{anb2n}\{a^n b^n\} \cup \{a^n b^{2n}\}.

    So DPDA ⊊\subsetneq NPDA in power:

    regular  ⊊  DCFL  ⊊  CFL.\text{regular} \;\subsetneq\; \text{DCFL} \;\subsetneq\; \text{CFL}.

    Strictness: anbna^n b^n is a DCFL but not regular; wwRww^R is context-free but not a DCFL.

    Acceptance by empty stack is weaker for DPDAs

    A DPDA that accepts by empty stack cannot move once the stack is empty. Therefore it can never accept a string and also a longer string that extends it: its language has the prefix property (no string of the language is a proper prefix of another). On 300 random deterministic PDAs accepting by empty stack the accepted language was prefix-free in every case. The language {anbn:n≥0}\{a^n b^n : n \ge 0\} contains ε\varepsilon, a prefix of every other string, so no DPDA accepts it by empty stack, although a DPDA accepts it by final state. The version with n≥1n \ge 1 is prefix-free and a deterministic empty-stack machine for it exists (checked). For nondeterministic PDAs the two acceptance conditions are equivalent (PDA).

    Closure properties

    operationregularDCFLCFL
    unionyesnoyes
    intersectionyesnono
    complementyesyesno
    concatenationyesnoyes
    staryesnoyes
    reversalyesnoyes
    intersection with a regular languageyesyesyes
    inverse homomorphismyesyesyes

    The DCFL column is a set of textbook results, quoted. Two of them can be explained: the product of a DPDA with a DFA is again a DPDA (checked), so DCFLs are closed under intersection with regular languages; and the complement is obtained by swapping the accepting states of a DPDA after making it complete and loop-free (the construction needs care with ε\varepsilon-loops and with states reached after the input ends). The union of two DCFLs is not always a DCFL: {aibjck:i=j}∪{aibjck:j=k}\{a^i b^j c^k : i = j\} \cup \{a^i b^j c^k : j = k\} is the union of two DCFLs but is not deterministic. From closure under complement and the failure of closure under union it follows that DCFLs are not closed under intersection either (De Morgan).

    Why DCFLs matter

    The languages generated by LR(kk) grammars are exactly the DCFLs (textbook theorem, quoted); LR parsers are DPDAs (LR parsing). Every DCFL has an unambiguous grammar (quoted), so inherently ambiguous languages and nondeterministic languages like wwRww^R cannot be parsed by an LR parser. LL(kk) grammars give a smaller class.

    Worked examples

    EX 1Is the PDA deterministic

    Easy

    δ(q0,a,Z)={(q0,AZ)}\delta(q_0, a, Z) = \{(q_0, AZ)\}, δ(q0,ε,Z)={(q1,Z)}\delta(q_0, \varepsilon, Z) = \{(q_1, Z)\}. Not deterministic: in state q0q_0 with top ZZ both an input move (aa) and an ε\varepsilon-move apply. If only δ(q0,ε,Z)\delta(q_0, \varepsilon, Z) existed (with no aa move on ZZ) it would be fine.

    EX 2Classify the language

    Easy

    {anbn}\{a^n b^n\}: DCFL, not regular. {a∗b∗}\{a^* b^*\}: regular. {wwR}\{w w^R\}: CFL, not a DCFL. {wcwR}\{w c w^R\}: DCFL. {anbncn}\{a^n b^n c^n\}: not context-free.

    EX 3Why the marker helps

    Medium

    For {wcwR}\{w c w^R\} the symbol cc occurs exactly once, in the middle. The DPDA stays in the pushing state until it reads cc, then moves to the popping state: in each state and for each input symbol exactly one move applies. Without cc (wwRww^R) the symbol just read could be the last of ww or the first of wRw^R, and the machine has two choices.

    EX 4Union of two DCFLs

    Medium

    L1={aibick}L_1 = \{a^i b^i c^k\} and L2={aibjcj}L_2 = \{a^i b^j c^j\} are DCFLs, but L1∪L2L_1 \cup L_2 is not (quoted): the machine would have to decide while reading the aa's whether to compare aa's with bb's or bb's with cc's, and it cannot postpone the decision since the stack must be used for one comparison. The union is a context-free language, so context-free languages are closed under union while DCFLs are not.

    EX 5Typical questions

    GATE level

    (a) "Every NPDA can be converted to an equivalent DPDA." False. (b) "DPDA with acceptance by empty stack equals DPDA with acceptance by final state." False (the first accepts only prefix-free languages). (c) "The complement of a DCFL is a DCFL." True. (d) "The complement of a CFL is always a CFL." False. (e) "The language of an LR(1) grammar is deterministic." True. (f) "Which is a DCFL: {anbn}\{a^n b^n\}, {wwR}\{w w^R\}, {anbncn}\{a^n b^n c^n\}?" Only the first. (g) "Is every DCFL unambiguous?" There is an unambiguous grammar for it (true).

    Cheat box

    Cheat box

    • DPDA: at most one move in every configuration; an ε\varepsilon-move must not compete with an input move. DCFL = accepted by a DPDA by final state.
    • regular ⊊\subsetneq DCFL ⊊\subsetneq CFL. anbna^n b^n, wcwRwcw^R, equal counts, balanced: DCFL. wwRww^R, i=ji = j or j=kj = k: CFL not DCFL.
    • DPDA by empty stack accepts only prefix-free languages.
    • DCFL closed under complement, intersection with regular, inverse homomorphism; not under union, intersection, concatenation, star, reversal.
    • LR(kk) languages = DCFLs; DCFLs have unambiguous grammars.

    Traps and GATE patterns

    Connections

    DCFLs are the languages of LR parsing in compilers (LR parsing); the closure properties of the whole class of CFLs are on the next page (closure of CFLs); the place of DCFLs in the Chomsky hierarchy is on the hierarchy page.

    PYQs

    9 previous year questions from your book. I re-solved each one myself (2 by running or simulating, 7 by reasoning only); the book's key is shown next to my answer. All PYQs

    GATE 2011 · MCQ · 1 markQ55 · page 205 of the book
    Which of the following pairs have DIFFERENT
    expressive power?
    • (a)Deterministic finite automata (DFA) and Non- deterministic finite automata (NFA)
    • (b). Deterministic push down automata (DPDA) and Non-deterministic push down automata (NPDA)
    • (c). Deterministic single-tape Turning machine and Non-deterministic single tape Turning machine
    • (d). Single-tape Turning machine and multi-tape Turning machine
    GATE 2025 · Set 2 · MCQ · 1 markQ5 · page 225 of the book
    Which ONE of the following languages is accepted by a
    deterministic pushdown automaton?
    • (a)Any regular language.
    • (b)Any context-free language.
    • (c)Any language accepted by a non-deterministic pushdown automaton.
    • (d)Any decidable language.
    GATE 2022 · MSQ · 1 markQ13 · page 227 of the book
    Consider the following languages:
    L1 = {ww | w ∈ {a, b}* }
    L2 = {anbncm | m, n≥ 0}
    L3 = {ambncn | m, n≥ 0}
    Which of the following statements is/are FALSE?
    • (a)L1 is not context-free but L2 and L3 are deterministic context-free
    • (b)Neither L1 nor L2 is context-free.
    • (c)L2, L3, and L2 ∩ L3 all are context-free.
    • (d)Neither L1 nor its complement is context-free.
    GATE 2016 · Set 1 · MCQQ27 · page 228 of the book
    Consider the transition diagram of a PDA given below
    with input alphabet Σ = {a,b} and stack alphabet Γ =
    {X,Z}. Z is the initial stack symbol. Let L denote the
    language accepted by the PDA.
    
    Which one of the following is TRUE?
    • (a)L = {anbn | n>= 0} and is not accepted by any finite automata
    • (b)L = {an| n >= 0} {anbn ∪ | n > =0} and is not accepted by any deterministic PDA.
    • (c)L is not accepted by any Turning machine that halts on every input.
    • (d)L = {an| n >= 0} {anbn ∪ | n > =0} and is deterministic context-free. THEORY OF COMPUTATION
    GATE 2009 · MCQQ32 · page 229 of the book
    Which one of the following is FALSE?
    • (a)There is a unique minimal DFA for every regular language
    • (b)Every NFA can be converted to an equivalent PDA.
    • (c)Complement of every context-free language is recursive.
    • (d)Every nondeterministic PDA can be converted to an equivalent deterministic PDA.
    GATE 2008 · MCQ · 2 marksQ37 · page 230 of the book
    Consider the following languages.
    L1={ai b j ck | i =j, k>=1}
    L2={ai b j | j=2i , i >=0}
    Which of the following is true?
    • (a)L1 is not a CFL but L2 is
    • (b)L1 ∩ L2 = φ and L1 is non –regular
    • (c)L1 U L2 is not a CFL but L2 is
    • (d)There is a 4- state PDA that accepts L1 ,but there is no DPDA that accepts L2.
    GATE 2006 · MCQ · 1 markQ45 · page 231 of the book
    Which of the following languages is accepted by a non-
    deterministic pushdown automaton (NPDA) but NOT
    by a deterministic NPDA?
    • (a){ anbncn | n≥0}
    • (b){albmcn | l ≠ m or m≠n }
    • (c){anbn | n>=0}
    • (d){ambn m,n >=0}
    GATE 2005 · MCQ · 1 markQ47 · page 231 of the book
    Consider the languages:
    
    L1 = {wwr | w ∈ {0, 1}*}
    
    L2 = {w#wr | w ∈ {0, 1}*}, where # is a special
    symbol
    
    L3 = {ww | w ∈ {0, 1}*}
    Which one of the following is TRUE?
    • (a)L1 is a deterministic CFL
    • (b)L2 is a deterministic CFL
    • (c)L3 is a CFL, but not a deterministic CFL
    • (d)L3 is a deterministic CFL
    GATE 2007 · MCQ · 2 marksQ24 · page 244 of the book
    The language L={ 0i21i | i≥0 } over the alphabet {0,1,2}
    is:
    • (a)not recursive
    • (b)is recursive and is a deterministic CFL
    • (c)is a regular language
    • (d)is not a deterministic CFL but a CFL

    Self-check

    Question 1

    Is {anbn:n≥0}\{a^n b^n : n \ge 0\} accepted by a DPDA that accepts by empty stack?

    Show answer

    No. The language contains ε\varepsilon, a proper prefix of every other string, but such a DPDA accepts only prefix-free languages. By final state it is accepted.

    Question 2

    Why can a DPDA accept wcwRw c w^R but not wwRw w^R?

    Show answer

    The marker cc shows where the middle is; without it the machine would have to guess the middle.

    Question 3

    Are DCFLs closed under complement? Under union?

    Show answer

    Complement: yes. Union: no.

    Question 4

    Give a PDA move set that is not deterministic although its language is a DCFL.

    Show answer

    The first design for equal numbers of aa and bb: an ε\varepsilon-move on ZZ to an accepting state next to the input moves on ZZ. A deterministic version exists.

    Revision card

    One-screen revision

    • DPDA: one move at most; ε\varepsilon must not compete with input.
    • regular ⊊\subsetneq DCFL ⊊\subsetneq CFL; wwRww^R is not deterministic.
    • DPDA by empty stack: prefix-free only.
    • DCFL: complement yes, union/intersection/concatenation/star/reversal no. LR(kk) = DCFL.

    References

    • ·Sipser, Introduction to the Theory of Computation (3rd edition), Section 2.4 (deterministic context-free languages)
    • ·Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation (3rd edition), Section 6.4 (deterministic pushdown automata), Section 7.3.2 (closure of DCFLs)

    Verification

    scripts/enum-checks/toc_cfl.py: five deterministic PDAs (a^n b^n, equal numbers of a and b, w c w^R, balanced parentheses, a^n b^n with n >= 1 by empty stack) equal their predicates on all strings up to length 10 (12 for parentheses) and pass the determinism test; the nondeterministic designs for ww^R, equal counts (first version), balanced parentheses (first version) and i = j or j = k fail it (the first versions have an epsilon-move next to input moves); the product of a DPDA with a DFA is again deterministic and accepts the intersection; on 300 random deterministic PDAs accepting by empty stack the language is prefix-free; a^n b^n with n >= 0 contains the empty string, a proper prefix of every other string, so it cannot be accepted by empty stack by a DPDA. The theorems that ww^R, {a^i b^j c^k : i = j or j = k} and {a^n b^n} union {a^n b^2n} are not deterministic, the closure table for DCFLs, DCFL = languages of LR(k) grammars, and 'DCFLs are unambiguous' are standard textbook results, QUOTED and NOT machine-proved here (needs verification). Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (state counts, derivations, parse-tree and move counts, decomposition counts); tables and animations are machine output and were read, not re-run; No other defect found. Status raised to self-checked; verified needs a textbook or human check.

    last verified: never