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 is deterministic (a DPDA) if in every configuration at most one move is possible. Formally, for all , :
- has at most one element for every ;
- if then for every (an -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 -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
(), the machine of the PDA page: push on , pop on , an -move to the final state only when the bottom marker shows and no input move applies. Its start state is also accepting (for ) so no -move competes with the move on .
(a marked palindrome, ): the marker tells the machine where the middle is, so no guessing is needed. Push the symbols of ; on 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 typedPushdown 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.
| state, top | a | b | c | ε |
|---|---|---|---|---|
| q0, a | q0,aa | q0,ba | q1,a | |
| q0, b | q0,ab | q0,bb | q1,b | |
| q0, Z | q0,aZ | q0,bZ | q1,Z | |
| q1, a | q1,ε | |||
| q1, b | q1,ε | |||
| q1, Z | q2,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.
Equal numbers of and and balanced parentheses: the stack holds the surplus. The first versions in these pages end with an -move into an accepting state at any time, which competes with the input moves: nondeterministic. The deterministic versions use a state that means "only the bottom marker is on the stack" and is accepting, and a special symbol for the lowest surplus symbol, so popping returns to . Both languages are DCFLs (the machines were checked on all strings up to length or ).
Nondeterministic is stronger: no DPDA for
The set of even palindromes is context-free but is not a DCFL. Intuition: after reading the machine must be ready for two different futures: the middle may have been after (then the string continues with , giving ) or after (then it continues with , giving ). 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 (it needs to guess which comparison to make) and for .
So DPDA NPDA in power:
Strictness: is a DCFL but not regular; 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 contains , 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 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
| operation | regular | DCFL | CFL |
|---|---|---|---|
| union | yes | no | yes |
| intersection | yes | no | no |
| complement | yes | yes | no |
| concatenation | yes | no | yes |
| star | yes | no | yes |
| reversal | yes | no | yes |
| intersection with a regular language | yes | yes | yes |
| inverse homomorphism | yes | yes | yes |
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 -loops and with states reached after the input ends). The union of two DCFLs is not always a DCFL: 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() 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 cannot be parsed by an LR parser. LL() grammars give a smaller class.
Worked examples
EX 1Is the PDA deterministic
Easy, . Not deterministic: in state with top both an input move () and an -move apply. If only existed (with no move on ) it would be fine.
EX 2Classify the language
Easy: DCFL, not regular. : regular. : CFL, not a DCFL. : DCFL. : not context-free.
EX 3Why the marker helps
MediumFor the symbol occurs exactly once, in the middle. The DPDA stays in the pushing state until it reads , then moves to the popping state: in each state and for each input symbol exactly one move applies. Without () the symbol just read could be the last of or the first of , and the machine has two choices.
EX 4Union of two DCFLs
Mediumand are DCFLs, but is not (quoted): the machine would have to decide while reading the 's whether to compare 's with 's or 's with '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: , , ?" 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 -move must not compete with an input move. DCFL = accepted by a DPDA by final state.
- regular DCFL CFL. , , equal counts, balanced: DCFL. , or : 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() languages = DCFLs; DCFLs have unambiguous grammars.
Traps and GATE patterns
Connections
Builds on
Across subjects
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
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
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.
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.
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
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.
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.
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}
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
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 accepted by a DPDA that accepts by empty stack?
Show answerHide
No. The language contains , 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 but not ?
Show answerHide
The marker 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 answerHide
Complement: yes. Union: no.
Question 4
Give a PDA move set that is not deterministic although its language is a DCFL.
Show answerHide
The first design for equal numbers of and : an -move on to an accepting state next to the input moves on . A deterministic version exists.
Revision card
One-screen revision
- DPDA: one move at most; must not compete with input.
- regular DCFL CFL; is not deterministic.
- DPDA by empty stack: prefix-free only.
- DCFL: complement yes, union/intersection/concatenation/star/reversal no. LR() = 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
My notes (saved in this browser)