Sub topic 9
Acceptance by Final State and by Empty Stack
Prerequisites and the two conventions
This chapter assumes that you know the definition of a pushdown automaton (PDA), including states, input symbols, stack symbols, and transitions. A stack is a last-in, first-out memory structure. The PDA reads an input string while changing its state and stack.
A PDA starts in an initial state with a bottom-of-stack symbol, often written as \(Z_0\). It accepts an input only after the entire input has been consumed. There are two common acceptance conventions.
| Convention | Condition for acceptance |
|---|---|
| Final state | The input is consumed and the PDA is in an accepting state |
| Empty stack | The input is consumed and the stack is empty |
Under final-state acceptance, the stack may contain symbols when the PDA accepts. Under empty-stack acceptance, the current state does not matter once the stack becomes empty.
Example: recognizing \(a^n b^n\)
Consider the language
\[ L=\{a^n b^n\mid n\geq 1\}. \]
A PDA can push one marker for every a, then pop one marker for every b. It accepts when all input is consumed and all markers have been removed.
Input: a a b b
Stack: Z0
A Z0 after reading the first a
A A Z0 after reading the second a
A Z0 after reading the first b
Z0 after reading the second bFor empty-stack acceptance, the PDA must also remove \(Z0\), or define the bottom marker as removable at the end. For final-state acceptance, it can enter an accepting state when the input ends and only \(Z0\) remains.
Converting between the conventions
For nondeterministic PDAs, final-state and empty-stack acceptance describe exactly the same class of languages.
To convert final-state acceptance to empty-stack acceptance:
- Add a new stack-bottom marker below the original stack.
- Let the PDA nondeterministically move from an accepting state to a cleanup state.
- In the cleanup state, pop every remaining stack symbol.
- Accept when the stack becomes empty.
The cleanup move must be possible only after the input has been consumed.
To convert empty-stack acceptance to final-state acceptance:
- Add a new accepting state.
- Add a fresh bottom marker.
- When the original PDA empties its stack, use an epsilon transition to enter the new accepting state.
- Accept only after all input has been consumed.
Important distinction for deterministic PDAs
The equivalence above relies on nondeterministic choices, especially the choice of when to begin cleanup. For general PDAs, the two conventions are interchangeable. For deterministic PDAs, acceptance by final state and acceptance by empty stack need not have the same expressive power.
When solving a problem, first identify the acceptance convention. A PDA that reaches a final state may still have symbols on its stack. A PDA accepting by empty stack may finish in a non-final state.
Exercise
A PDA consumes all input and ends in state q_accept, but its stack still contains A Z0. Does it accept under final-state acceptance? Does it accept under empty-stack acceptance?
Show answer
It accepts under final-state acceptance if q_accept is an accepting state. It does not accept under empty-stack acceptance because the stack is not empty.