Pushdown_Automata
Pushdown Automata (PDA) – Complete Exam Preparation
Full Notes with Examples, Conversions, Pumping Lemma & Exam Tips
1. Pushdown Automaton – Definition
A Pushdown Automaton (PDA) is a 7-tuple:
M = (Q, Σ, Γ, δ, q₀, Z₀, F) where:
| Component | Meaning |
|---|---|
| Q | Finite set of states |
| Σ | Input alphabet |
| Γ | Stack alphabet (Γ ⊃ Σ usually) |
| δ | Transition function: Q × (Σ ∪ {ε}) × Γ → finite set of (Q × Γ*) |
| q₀ | Initial state |
| Z₀ | Initial stack symbol (usually Z or $) |
| F ⊆ Q | Set of final (accepting) states |
Two Types of Acceptance
| Type | Acceptance By | Most Common in Exams |
|---|---|---|
| Acceptance by Final State | End in q ∈ F (stack may have garbage) | Yes |
| Acceptance by Empty Stack | Stack becomes empty (state doesn't matter) | Yes |
Both are equivalent in power → recognize exactly Context-Free Languages
2. Instantaneous Description (ID)
Represented as: (current state, remaining input, current stack)
Example: (q₁, 0011, AZB)
3. Important PDA Designs (Must Know)
1. PDA for { aⁿ bⁿ | n ≥ 0 } (Classic)
Idea: Push a on stack for each a, pop a for each b
Idea: Push a on stack for each a, pop a for each b
δ(q0, a, Z) = (q0, aZ) → push a δ(q0, a, a) = (q0, aa) → push a δ(q0, ε, Z) = (q1, Z) → move to q1 δ(q1, b, a) = (q1, ε) → pop a δ(q1, ε, Z) = (qf, Z) → accept (final state)
2. PDA for { wwʳ | w ∈ {a,b}* } (Palindromes)
Phase 1: Push all input
Phase 2: After nondeterministic ε-move, start matching reverse
Phase 1: Push all input
Phase 2: After nondeterministic ε-move, start matching reverse
δ(q0, a, Z) = (q0, aZ), δ(q0, b, Z) = (q0, bZ) δ(q0, ε, Z) = (q1, Z) → guess middle δ(q1, a, a) = (q1, ε), δ(q1, b, b) = (q1, ε) Accept by empty stack
3. PDA for Even-length palindromes
Same as above but reject odd length by requiring center symbol.
Same as above but reject odd length by requiring center symbol.
4. Equivalence: CFG ↔ PDA (Most Important Theorem)
Theorem: A language is Context-Free ⇔ it is accepted by a PDA
→ L(PDA) = L(CFG)
→ L(PDA) = L(CFG)
Conversions (Frequently Asked)
| Conversion | Method | Difficulty |
|---|---|---|
| CFG → PDA | Standard construction (push RHS, pop LHS) | Medium |
| PDA → CFG | Using variables [q X p] meaning "go from q to p popping X at top" | Hard (10–15 marks) |
Standard CFG → PDA Construction (Remember Steps)
- Start: (q₀, ε, S$) → (q, ε, RHS$)
- For terminal: (q, a, a) → (q, ε, ε)
- For variable: (q, ε, A) → (q, ε, RHS)
- Accept by empty stack
5. Deterministic vs Non-deterministic PDA
| Type | Power | Examples of Languages NOT Accepted by DPDA |
|---|---|---|
| DPDA | Proper subset of CFL | {wwʳ} is NOT accepted by DPDA (needs nondeterminism to guess middle) |
| NPD | All CFLs | — |
6. Pumping Lemma for Context-Free Languages (Killer Question)
CFL Pumping Lemma:
If L is CFL, then ∃ p such that ∀ w ∈ L with |w| ≥ p,
w = uvxyz such that:
1. |vxy| ≤ p
2. |vy| ≥ 1
3. ∀ k ≥ 0, uvᵏ x yᵏ z ∈ L
If L is CFL, then ∃ p such that ∀ w ∈ L with |w| ≥ p,
w = uvxyz such that:
1. |vxy| ≤ p
2. |vy| ≥ 1
3. ∀ k ≥ 0, uvᵏ x yᵏ z ∈ L
How to Prove Language is NOT CFL
- Assume L is CFL → ∃ p
- Choose smart w (usually aᵖ bᵖ cᵖ dᵖ or aᵖ bᵖ aᵖ bᵖ)
- Show that for some k (usually k=0 or k=2), uvᵏxyᵏz ∉ L
Prove {aⁿ bⁿ cⁿ | n ≥ 0} is NOT CFL
Let w = aᵖ bᵖ cᵖ
w = uvxyz, |vxy| ≤ p, |vy| ≥ 1
→ vxy can cover at most 2 symbols
→ pumping k=2 → one symbol gets more count → not equal → contradiction
Let w = aᵖ bᵖ cᵖ
w = uvxyz, |vxy| ≤ p, |vy| ≥ 1
→ vxy can cover at most 2 symbols
→ pumping k=2 → one symbol gets more count → not equal → contradiction
7. Closure Properties of CFLs (Important)
| Operation | Closed? | Counterexample if No |
|---|---|---|
| Union | Yes | — |
| Concatenation | Yes | — |
| Kleene Star | Yes | — |
| Intersection | No | {aⁿbⁿcⁿ} = {aⁿbⁿ} ∩ {bⁿcⁿ} |
| Complement | No | — |
| Difference | No | — |
| Intersection with Regular | Yes | — |
8. Most Important Exam Questions – Unit IV
- Design PDA for {aⁿbⁿ}, {wwʳ}, {aⁿb²ⁿ}, equal number of a,b,c etc. (8–12 marks)
- Convert given CFG to PDA (step-by-step)
- Prove given language is not CFL using Pumping Lemma (aⁿbⁿcⁿ, aᵐbⁿcᵐdⁿ)
- Show two PDAs are equivalent
- Difference between DPDA and NPDA
- Prove closure properties with examples
- Construct PDA accepting by final state vs empty stack
Quick Revision One-Liners
- PDA = FA + One Stack → Context-Free
- wwʳ needs nondeterminism → not accepted by DPDA
- CFLs not closed under intersection → hence not complement
- Pumping: uvᵏxyᵏz must stay in language
- Always choose w with p exponents
- Stack is LIFO → perfect for matching parentheses, nested structures