Recall warm-up
- What does empty-stack acceptance require?
Stuck? Peek at 3.3.2 Acceptance by final state vs empty stack
- Final state: input read, state ∈ F, stack anything. Empty stack: input read, stack empty, state anything.
- NPDA: both conventions = CFL (convert with a new bottom marker).
- DPDA: empty stack ⇒ only prefix-free DCFLs; final state ⇒ all DCFLs. GATE default: final state.
- What is an ID of a PDA?
Stuck? Peek at 3.3.1 Stack primer and the push-down automaton
- PDA (Q, Σ, Γ, δ, q₀, Z₀, F); δ(q, a|ε, X) ⊆ Q × Γ*; label a, X/γ (γ = ε pop, X keep, YX push).
- ID (q, w, γ), top first; ⊢ one move, ⊢* many.
- Nondeterministic by default; ε-moves still see the stack.
- Does nondeterminism add power to finite automata?
Stuck? Peek at 1.2.3 Subset construction and the 2ⁿ blow-up
- Subset construction: start {q₀} (or ECLOSE(q₀)); δ(S,a) = ⋃ δ(q,a) (then ECLOSE); accept iff S ∩ F ≠ ∅; ∅ = dead state.
- ≤ 2ⁿ states; count only reachable sets.
- ε-removal: δ'(q,a) = ECLOSE(δ(ECLOSE(q), a)); F' = {q : ECLOSE(q) ∩ F ≠ ∅}.
- k-th from end is 1: NFA k+1, DFA 2ᵏ. k-th from start: DFA k+2.
- DFA ≡ NFA ≡ ε-NFA in power.
The Hook
For finite automata, guessing was only a convenience. For stack machines it is real power: to check that a string is an even palindrome, the machine must switch from “remembering” to “checking” exactly at the middle — and nothing in the string marks the middle. A guessing PDA tries every position; a deterministic one cannot. This lesson builds PDAs by recipe and draws the first strict line inside the context-free family.
Predict First
wcwᴿ (a c in the middle) vs wwᴿ (no marker). Which one can a PDA handle without guessing?
Core Concept
Prediction check
wcwᴿ: push until c, then pop and match. With wwᴿ the machine must guess where the middle is.
A design recipe
- Decide what the stack stores (one symbol per a; the surplus of a’s over b’s; the first half).
- Use states for the phase (pushing, popping, done) and any finite information.
- Use Z₀ to detect “stack otherwise empty”.
- Accept with an ε-move on Z₀ into a final state.
- Trace one accepted and two rejected strings.
Balanced parentheses and equal counts
Balanced: push X on (, pop on ), accept on Z₀. Equal #a and #b: the stack holds the surplus — A’s if a’s lead, B’s if b’s lead; a matching opposite symbol pops.
Deterministic PDAs
A language accepted by a DPDA (final state) is a deterministic context-free language (DCFL).
Regular ⊂ DCFL ⊂ CFL (both strict)
- Every regular language is a DCFL (a DFA is a DPDA that ignores its stack). aⁿbⁿ is a DCFL but not regular.
- Every DCFL is a CFL. wwᴿ (even palindromes) is a CFL but not a DCFL; so is { aⁿbⁿ } ∪ { aⁿb²ⁿ } and { aⁱbʲcᵏ : i = j or j = k }.
- Every DCFL has an unambiguous grammar — but some unambiguous CFLs (like wwᴿ) are not DCFLs.
Contrast: NFA = DFA in power, but NPDA > DPDA.
Putting it together
- Design PDAs by deciding what the stack stores and which phase each state represents.
- DPDAs forbid competing moves; they accept the DCFLs.
- Regular ⊊ DCFL ⊊ CFL: guessing adds power to stack machines.
Visual
trace of abba on the wwᴿ NPDA (the accepting branch) (q0,abba,Z) ⊢ (q0,bba,AZ) ⊢ (q0,ba,BAZ) ⊢ε (q1,ba,BAZ) ⊢ (q1,a,AZ) ⊢ (q1,ε,Z) ⊢ε (q2,ε,Z) ACCEPT the branch that guesses the middle after 1 symbol: (q1,bba,AZ) — b vs A: stuck. Only the right guess survives.
Worked Examples
Design a PDA for { aⁿb²ⁿ : n ≥ 0 }.
Show the full solution
On each a push AA; on each b pop one A; accept when Z₀ is on top with input finished. Trace aabbbb: stack AAAAZ, four pops, Z ⇒ accept. abbb: one extra b with Z on top ⇒ reject.
Is { aⁿbᵐ : n ≥ m } a DCFL?
Show the full solution
Yes: push for a’s, pop for b’s (reject if Z₀ appears before b’s end), accept at the end regardless of leftover A’s. No guessing needed.
Which are DCFLs? (i) { wcwᴿ } (ii) { wwᴿ } (iii) { aⁿbⁿ } ∪ { aⁿb²ⁿ } (iv) { aⁿbᵐcⁿ : n, m ≥ 0 }
Show the full solution
(i) DCFL (marker). (ii) not (must guess the middle). (iii) not: after reading aⁿbⁿ the machine must decide whether to stop matching or continue at ratio 2 — it would need to remember both the count and still check twice. (iv) DCFL: push a’s, skip b’s, pop on c’s. Answer: (i) and (iv).
GATE Traps
- NFA = DFA, but NPDA ⊋ DPDA. Don’t transfer the finite-automaton result.
- An unambiguous CFL need not be a DCFL (wwᴿ).
- A DPDA may still have ε-moves — just never in competition with input moves on the same state and top.
- Regular ⊂ DCFL: every regular language is deterministic context-free.
Memory Hook
A marker in the middle (c) is a signpost: the cautious traveller (DPDA) needs one; the guesser (NPDA) does not.
Connect the Dots
PDAs and CFGs both describe context-free languages — so far that is a claim. The next lesson connects them: every grammar becomes a PDA, and every PDA becomes a grammar.
Self-Test
- MSQ
Which languages are DCFLs?
- { aⁿbⁿ }
- balanced parentheses
- { wwᴿ : w ∈ {a,b}* }
- { w c wᴿ }
- MCQ
Which is true?
- NPDA and DPDA are equally powerful
- Every CFL is a DCFL
- Every DCFL has an unambiguous grammar
- Every unambiguous CFL is a DCFL
- MCQ
A PDA has δ(q, ε, Z) = {(p, Z)} and δ(q, a, Z) = {(r, AZ)}. It is:
- deterministic
- not deterministic
- deterministic only if p = r
- not a valid PDA
- NAT
In the wwᴿ NPDA, how many guesses of the middle are possible while reading a string of length 6 (positions 0…6)?
Write your answer before opening the key.
Rule Card
- Recipe: stack stores what is unbounded; states store the phase; Z₀ detects empty; accept via ε, Z₀.
- DPDA: ≤ 1 move per (q, a|ε, X), and no ε-move competing with input moves.
- Regular ⊊ DCFL ⊊ CFL. wwᴿ, aⁿbⁿ ∪ aⁿb²ⁿ, aⁱbʲcᵏ (i=j or j=k): CFL not DCFL.
- DCFL ⇒ unambiguous grammar; not conversely.
Concept Ledger
- deterministic PDA (DPDA)
- deterministic CFL (DCFL)
- NPDA
- Regular ⊂ DCFL ⊂ CFL
- PDA design recipe
Answer Vault
Reveal answers when you’re ready
Warm-up answers
- Input fully read and the stack completely empty.
- (state, unread input, stack top-first).
- No — subset construction gives an equivalent DFA.
Self-test answers
- ABD — No guessing needed.
- C: Must guess the middle.
- C — Determinism gives a unique computation, hence an unambiguous grammar.
- A: NPDA is strictly stronger.
- B: wwᴿ is not.
- D: wwᴿ is unambiguous but not a DCFL.
- B — ε-move and input move compete on (q, Z).
- A: Violates condition 2.
- C: States do not matter.
- D: It is a valid (nondeterministic) PDA.
- 7 — The ε-move can be taken before any of the 7 positions.
Flashcards
- Is NPDA strictly more powerful than DPDA?
Reveal answer
Yes (wwᴿ). Unlike NFA vs DFA. - Standard CFL that is not a DCFL?
Reveal answer
wwᴿ (even palindromes). - Does every DCFL have an unambiguous grammar?
Reveal answer
Yes. - Two DPDA conditions?
Reveal answer
At most one move per (q, a|ε, X); no ε-move on (q, X) if there is an input move on (q, X).