BCS402 · Theory of Automata and Formal Languages · Unit 4
Push Down Automata and Properties of Context Free Languages
Unit Scope & Exam Weightage: This unit covers NPDA definition and moves, acceptance by final state and empty stack, DPDA and deterministic CFLs, PDA construction for CFLs, CFG from PDA, two-stack PDA, pumping lemma for CFL, closure and decision properties, and programming problems on CFL properties. Expect 7-mark constructions (PDA diagrams/transition tables) and 2-mark definitions/comparisons.
Importance-Wise Roadmap (BCS402 Unit 4)
| Priority | Exact Syllabus Topic | PYQ Evidence | Marks Pattern | Tag |
|---|---|---|---|---|
| 1 | PDA construction for CFL (palindrome, a^n b^2n, CFG→PDA) | 2023-24 (PYQ), predicted clusters 2023-26 | 7m × 4 | Core construction |
| 2 | Two-stack PDA (a^n b^n c^n) | 2023-24, 2025-26 | 7m + 2m | Power argument |
| 3 | DPDA vs NPDA / DCFL | 2023-24, 2025-26 | 7m × 2 | Comparison |
| 4 | CFG from given PDA | 2023-24 | 7m | [qXp] rules |
| 5 | Acceptance by final state / empty stack | 2025-26 | 2m | Definitions |
| 6 | CFL pumping lemma, closure, decision problems | Not directly asked | Predicted | Theory backup |
PDA-specific examiner guidance: Always show the stack content after each input symbol in an instantaneous-description (ID) sequence. A construction answer must state the stack bottom marker , the push/pop convention (leftmost symbol = top), and the acceptance mode.
1. Pushdown Automaton — Model and Moves
Nondeterministic Pushdown Automaton (NPDA): a 7-tuple where = finite states, = input alphabet, = stack alphabet, finite subsets of , = start state, = initial stack bottom symbol, = final states. The stack gives unbounded memory with LIFO access.
1.1 Moves and Instantaneous Descriptions
An ID (instantaneous description) is : current state , unread input , stack content with the leftmost symbol on top.
| Move type | Transition | ID transition |
|---|---|---|
| Consume input, replace top | ||
| ε-move (no input consumed) |
Acceptance:
- By final state: accepted if some computation ends in with (stack content irrelevant).
- By empty stack: accepted if some computation ends in — the stack is empty. The two modes are equivalent: a PDA accepting by final state can be converted to one accepting by empty stack and vice versa.
PYQ (2025-26, 2 marks): "Define acceptance by final state and acceptance by empty stack in a PDA." Use the two bullet definitions above; add that in empty-stack acceptance the final-state set may be ignored, while final-state acceptance does not require an empty stack.
1.2 DPDA and DCFL
| Feature | DPDA | NPDA |
|---|---|---|
| Transition per | At most one | Finitely many |
| ε-moves | Restricted (no ambiguous ε/input choice) | Unrestricted |
| Languages accepted | Deterministic CFLs (DCFL), a proper subset of CFL | All CFLs |
| Parser | Deterministic (LR-style), efficient | Needs backtracking |
| Complement closure | Closed under complement | Not closed under complement |
PYQ (2025-26, 7 marks): "Why are NPDAs considered more powerful than DPDAs? Provide an example of a language accepted by NPDA but not by DPDA." Nondeterminism lets the machine guess the middle of a string or which branch of a grammar to use. Example: over (even-length palindromes). The NPDA pushes symbols until it guesses the midpoint, then must match; no DPDA can know where the second half starts because there is no delimiter. Hence is CFL but not DCFL.
PYQ (2023-24, 7 marks): "Differentiate between DPDA and NPDA. Construct a PDA that accepts language L={a^n b^n | n≥1}." Use the table, then the construction below. Note is deterministic (the switch from
atobis visible in the input).
PDA for (empty stack):
q0: (q0, a, z0) -> (q0, a z0) // push first a under z0
(q0, a, a) -> (q0, a a) // push further a's
(q0, b, a) -> (q1, ε) // see first b: start popping, switch state
q1: (q1, b, a) -> (q1, ε) // pop one a per b
(q1, ε, z0) -> (q1, ε) // empty stack -> accept
ID trace for aaabb:
✔
For aabb the last step would leave two as on the stack → rejected.
2. PDA Constructions for CFLs
2.1 PDA for
Predicted (bank
PRED, 2025-26, 7 marks): "Construct PDA that accepts L={a^n b^{2n} | n≥1}."
Idea: push two markers for each a, then pop one marker per b.
q0: (q0, a, z0) -> (q0, X X z0) // first a: push two X below z0
(q0, a, X) -> (q0, X X X) // each further a: net +2 X
(q0, b, X) -> (q1, ε) // first b: begin popping
q1: (q1, b, X) -> (q1, ε) // pop one X per b
(q1, ε, z0) -> (q1, ε) // accept when stack empties
Trace aabb (n=2, need 4 b's): after aa stack = XXXX z0; after four bs stack = z0 → ε → accepted. aaabb (5 b's) fails: no X to pop for the fifth b. aabbb (3 b's) fails: one X remains.
2.2 PDA for Palindromes /
Predicted (bank
PRED, 2024-25, 7 marks ×2): "Design a PDA that accepts L={ww^R | w∈{a,b}*} / palindromes over {a,b}"
q0: (q0, a, X) -> (q0, aX) for X in {a,b,z0} // push symbols while guessing first half
(q0, b, X) -> (q0, bX)
(q0, ε, X) -> (q1, X) // nondeterministic guess of the middle
q1: (q1, a, a) -> (q1, ε) // match a against top
(q1, b, b) -> (q1, ε) // match b against top
(q1, ε, z0) -> (q1, ε) // accept by empty stack
Trace abba: push a, push b; guess middle after ab; then input b matches top b, input a matches top a, ε-pops → accepted. The guess is what makes the automaton nondeterministic; a DPDA cannot make this choice uniquely without a centre marker.
2.3 CFG → PDA (top-down parsing construction)
For CFG , build PDA with , stack alphabet , start stack :
- For each production : (push RHS left-to-right so leftmost symbol is on top).
- For each terminal : (match and pop).
Example for , input aabb:
✔ — one leftmost derivation equals one PDA computation.
2.4 PDA → CFG (PYQ 2023-24, 7 marks)
PYQ: "Find the equivalent CFG of PDA P=({q0,q1},{a,b},{a,z0},δ,q0,z0) where δ(q0,a,z0)=(q0,az0), δ(q0,a,a)=(q1,aa), δ(q1,a,a)=(q1,ε), δ(q1,ε,z0)=(q1,ε)."
Use variables meaning "starting at state with on top, the PDA can reach state having popped ".
Construction rules:
- If , add .
- If , add for all choices of intermediate states.
- If , add .
Applying them:
- From : .
- From : .
- From : .
- From with the final state chosen as : .
Equivalent CFG: (with supporting variables , , ). Check by simulation: the PDA accepts only the string aaaa, as shown by pushing at the first a, switching at the second, and popping two as with the remaining two input symbols before ε-popping .
2.5 Two-Stack PDA
PYQ (2025-26, 7 marks): "Design Two Stack Pushdown Automata for L={a^n b^n c^n | n≥1}." PYQ (2023-24, 2 marks): "Explain the concept of two stack PDA. Give an example of a language accepted by two stack PDA but not accepted by normal one stack PDA."
Design:
- Read the
ablock, pushing one markerXonto stack 1 for eacha. - Read the
bblock: pop oneXfrom stack 1 perb(checking count ofa= count ofb), and simultaneously push one markerYonto stack 2 perb. - Read the
cblock: pop oneYfrom stack 2 perc. - Accept if both stacks contain only their bottom markers at end of input.
Phase 1 (a's) Phase 2 (b's) Phase 3 (c's)
stack1: X X X pop X per b empty
stack2: z0 push Y per b pop Y per c -> empty
Why one stack is not enough: a single stack cannot both verify a against b and retain the count for c; popping to match b destroys the information needed later. Two stacks give Turing-machine-level memory, so (a non-CFL) is accepted. Example answer for 2 marks: two-stack PDA accepts ; a one-stack PDA cannot (pumping lemma for CFL shows it is not context-free).
3. Properties of Context-Free Languages
3.1 Pumping Lemma for CFL (predicted theory)
If is an infinite CFL, there is a pumping length such that any with can be written with:
- (something is pumped),
- (the pumped region is local),
- for all .
Application template: choose ; the short middle can cover at most two symbol types, so pumping changes one or two counts but not all three equally → contradiction; hence is not context-free.
3.2 Closure Properties
| Operation | CFL closed? | Reason |
|---|---|---|
| Union | Yes | New start |
| Concatenation | Yes | |
| Kleene star | Yes | |
| Intersection | No | , intersect to |
| Complement | No | Would make CFL closed under intersection via De Morgan |
| Intersection with regular language | Yes | Product of PDA and DFA |
| Difference with regular language | Yes | , and is regular |
3.3 Decision Problems
| Problem | Decidable for CFL? |
|---|---|
| Is ? | Yes — CYK / Earley parser |
| Is ? | Yes — find generating non-terminals |
| Is finite? | Yes — detect a useful cycle |
| Is ? | No (equivalence undecidable for CFL) |
| Is ? | No |
4. Exam-Ready and Practice Questions
Solved-question index
| Question | Section with full solution |
|---|---|
| Acceptance by final state vs empty stack (2025-26, 2m) | §1.1 |
| DPDA vs NPDA + PDA for (2023-24, 7m) | §1.2 |
| NPDA more powerful than DPDA (2025-26, 7m) | §1.2 |
| PDA for (predicted, 7m) | §2.1 |
| PDA for / palindromes (predicted, 7m ×2) | §2.2 |
| CFG from given PDA (2023-24, 7m) | §2.4 |
| Two-stack PDA for (2025-26, 7m; 2023-24, 2m) | §2.5 |
Practice questions (label: practice, not real PYQs)
- Practice: Give the ID sequence of the PDA on
aaabbb. - Practice: Modify the palindrome PDA to accept odd-length palindromes too.
- Practice: Convert into a PDA using the CFG→PDA algorithm.
- Practice: Show with the CFL pumping lemma that is not context-free.
- Practice: Explain why DCFLs are closed under complement but CFLs are not.
5. Last-Night Survival Checklist (Unit 4 only)
- 7-tuple: ; stack top is the leftmost symbol; write the bottom marker in every construction.
- Three constructions memorised: (deterministic), (push two, pop one), palindrome (guess middle).
- Two-stack argument: stack 1 checks
avsb, stack 2 checksbvsc; one stack cannot retain both counts. - PDA→CFG variables: ; terminal rule from ε-pop, chained rule from multi-symbol push.
- Closure traps: CFL union/concat/star yes; intersection/complement no; intersection with a regular language yes.
Final PDA reminder: A PDA answer without an ID trace is incomplete. Show at least one accepted string step-by-step and one rejected string that fails because of a leftover stack symbol; this demonstrates that the construction really implements the counting condition.