Run the simulation or press Step to see detailed explanations for each transition.
What is a Pushdown Automaton?
A powerful computational model that extends Finite Automata with an unbounded stack memory.
Informal Definition
A PDA is like a Finite Automaton but with a stack (LIFO memory). It reads input symbols one at a time and can push or pop symbols from the stack. The stack gives it more power — PDAs can recognize all Context-Free Languages, which FAs cannot.
Formal Definition
A PDA is a 7-tuple M = (Q, Σ, Γ, δ, q₀, Z₀, F) where:
Q— finite set of statesΣ— finite input alphabetΓ— finite stack alphabetδ— transition function: Q × (Σ ∪ {ε}) × Γ → P(Q × Γ*)q₀ ∈ Q— initial stateZ₀ ∈ Γ— initial stack symbolF ⊆ Q— set of accepting states
Acceptance
A string is accepted if the PDA reaches a final state after reading all input (acceptance by final state), or if the stack becomes empty (acceptance by empty stack).
vs Finite Automata
| Feature | FA | PDA |
|---|---|---|
| Memory | None | Unbounded Stack |
| Languages | Regular | Context-Free |
| aⁿbⁿ | ❌ | ✅ |
| wcwᴿ | ❌ | ✅ |
Acceptance Methods
In PDA theory, string acceptance determines whether a string belongs to the language. There are two equivalently powerful but conceptually distinct methods.
Acceptance by Final State (L(P))
A PDA accepts a string if, after consuming the entire input, it is in one of the designated final states (F). The stack contents are completely ignored.
Formal Definition:
Key Points:
- Final state qf must be in F
- Stack can contain any symbols x ∈ Γ*
- Mimics how Finite Automata accept strings
- Useful when language structure maps naturally to states
Acceptance by Empty Stack (N(P))
A PDA accepts a string if, after consuming the entire input, the stack is completely empty (often called the "null" or initial state of the stack). The current state is irrelevant.
Formal Definition:
Key Points:
- Stack must be empty (ε) after all input consumed
- Final state is irrelevant — any state q ∈ Q works
- Often simpler for languages where symbols must be matched exactly
- ε-transitions are crucial for "cleaning" the stack bottom Z₀
Key Differences Summary
| Feature | Empty Stack (N(P)) | Final State (L(P)) |
|---|---|---|
| Acceptance Criteria | Stack is empty (ε) | Machine is in qf ∈ F |
| Stack Content | Must be empty | Irrelevant (any x ∈ Γ*) |
| Final State | Irrelevant (any q ∈ Q) | Must be in F ⊆ Q |
| Equivalence | Yes (CFLs) | Yes (CFLs) |
⚡ Theorem: Both acceptance methods are equivalent in expressive power — every CFL accepted by one method can be accepted by the other. A PDA accepting by final state can always be converted to one accepting by empty stack, and vice versa.
ε-Transitions (Epsilon Moves)
What is an ε-Transition?
An ε-transition (epsilon move) allows the PDA to change state or manipulate the stack without consuming any input symbol. It is a "free move" purely driven by the stack top.
Notation: δ(q₁, ε, Z₀) = (qf, ε)
This means: from state q₁, if stack top = Z₀, move to qf and pop Z₀ — without reading any input.
Role in Acceptance
ε-transitions are critical for bridging between acceptance methods:
- Final State PDA: Use ε-transition from matching state to qf
- Empty Stack PDA: Use ε-transitions at end to pop remaining stack symbols
- Phase Switching: Move between phases (push → pop) without consuming input
- Multi-phase PDAs: ε-transitions connect computation phases cleanly
Classic Languages
L = { aⁿbⁿ | n ≥ 1 }
Equal number of a's and b's. Example: ab, aabb, aaabbb
Strategy: Push A for each 'a', pop A for each 'b'. Accept when stack returns to Z₀.
Balanced Parentheses
Correctly matched parentheses. Example: (), (()), (()())
Strategy: Push P for each '(' and pop for each ')'. Accept when stack empty at end.
L = { aⁿb²ⁿ | n ≥ 1 }
Twice as many b's as a's. Example: abb, aabbbb, aaabbbbbb
Strategy: Push 2 A's per 'a' (net +2). Pop 1 A per 'b'. Accept when 2n pops clear the stack.
L = { wcwᴿ | w ∈ {a,b}* }
Palindrome with explicit centre marker 'c'. Example: abcba, aabcbaa
Strategy: Push each symbol of w. On 'c', switch to pop mode and match wᴿ symbol by symbol.
Note: This requires a DPDA — the 'c' acts as an unambiguous pivot.
Summation Languages (Three-Variable)
These languages require multi-phase stack logic with ε-transitions between phases.
L = { aⁿbᵐcⁿ⁺ᵐ | n, m ≥ 1 }
Total c's = n+m. Example: abcc, aabccc, aabbcccc
Strategy: Push A for each 'a', push B for each 'b'. Stack depth = n+m. Pop one symbol per 'c'.
Phases: Push-a → Push-b → Pop-c
L = { aⁿbⁿ⁺ᵐcᵐ | n ≥ 1, m ≥ 0 }
First n b's match a's; extra m b's verified by c's. Example: ab, abbc, aabbbcc
Strategy: Push A per 'a'. Pop A per 'b' (n-match). When A's exhausted, push B for extra b's. Pop B per 'c'.
Phases: Push-a → Pop-A(b) → Push-B(b) → Pop-B(c)
L = { aⁿ⁺ᵐbᵐcⁿ | n, m ≥ 0 }
Push all a's (n+m), pop m for b's, pop n for c's. Example: ac, aabc, aaabcc
Strategy: Push A for every 'a'. Pop A per 'b' (the m-component). Pop A per 'c' (the n-component).
Phases: Push-a(n+m) → Pop-A(b) → Pop-A(c)
Transition Rules
δ(From, Input, StackTop) → (To, Push)
| # | From State | Input (ε ok) | Stack Top | → To State | Push (space-sep, ε=pop) |
|---|