Hello! Welcome back to our study of the Theory of Computation.
In the last lesson, we focused on designing Pushdown Automata (PDAs) that accept languages by final state. We saw how to devise a strategy using the stack for memory and translate that into the states and transitions of a PDA. The core condition was simple: after reading all input, the machine must be in one of its designated final states.
Today, we will explore an alternative, equally powerful method of acceptance: acceptance by empty stack. This lesson will cover three key objectives:
- Formally define and design PDAs that accept by emptying their stack.
- Learn the constructive algorithm to convert an empty-stack PDA into an equivalent final-state PDA.
- Learn the reverse algorithm: converting a final-state PDA into an equivalent empty-stack one.
Mastering these conversions is not just a theoretical exercise; it proves a fundamental theorem: that both acceptance criteria define the exact same class of languages—the Context-Free Languages. The algorithmic nature of these conversions should resonate with your background in building complex systems, as it's akin to creating a compiler or transpiler that transforms one formal specification into another while preserving its behavior.
1. Acceptance by Empty Stack
While acceptance by final state ignores the final stack contents, acceptance by empty stack does the opposite: it ignores the final state, but the stack must be empty.
Formal Definition
Let's start with a formal definition. A PDA accepts a string w by empty stack if, starting from the initial configuration, it can process the entire string w and end up in any state with a completely empty stack.
Pushdown Automata 1 Formal Definition
This document, 'Pushdown Automata 1 Formal Definition' by Hoogeboom and Engelfriet, provides a clear and rigorous definition of the two acceptance types. We'll focus on the definition for empty stack.
Please read the section titled 'Computations' on page 2. Focus on the formal definition of the empty stack language, denoted as N(A). Contrast this with the definition of the final state language, L(A), which we discussed in the previous lesson.
As defined in the text, the empty stack language of a PDA is:
The key components are:
- The input
wis fully consumed (leavingλ, the empty string). - The stack is completely empty (also
λ). - The state
qthe machine ends in is irrelevant.
Designing for an Empty Stack
When designing a PDA for empty stack acceptance, the goal is to make the stack empty if and only if the input string belongs to the language. This often means popping the initial stack marker at the very end as the final step of acceptance.
Let's consider a language we've seen before: . In the last module, we would design a PDA for this that ends in a final state. Now, let's design one that accepts by empty stack.
Strategy:
- Start with a symbol on the stack.
- For every
aat the beginning of the string, push a symbol (e.g.,X) onto the stack. - For the
b's in the middle, do nothing with the stack (skip them). - For every
cat the end, pop oneXfrom the stack. - If we finish reading the input and the stack contains only , it means the number of
a's andc's matched. We can then add a final transition to pop and empty the stack.
The following video shows a very similar strategy, though it's aimed at final state acceptance. Watch it to understand the core push/skip/pop logic.
Theory of Computation: PDA Example (a^n b^m c^n)
This video by Anita R demonstrates the PDA logic for a language very similar to ours. Focus on the core strategy of pushing for 'a's, ignoring 'b's, and popping for 'c's. We will then adapt this logic for empty stack acceptance.
Watch from the beginning until 04:51. Observe how the PDA uses the stack to ensure the count of 'a's matches the count of 'c's. Notice the final transition where the machine sees the bottom-of-stack marker.
To adapt the PDA shown in the video for empty stack acceptance, we would make a small but crucial change. Instead of the transition from q2 to a final state q3 that leaves the stack marker untouched (ε, Z / Z), we would define a transition that pops the marker:
- Original (Final State):
δ(q₂, ε, Z₀) = {(q_f, Z₀)} - Adaptation (Empty Stack):
δ(q₂, ε, Z₀) = {(q_any, ε)}
This final pop empties the stack, thus accepting the string by our new criterion. If the input was malformed (e.g., too many c's or too few), the machine would either get stuck or end with a non-empty stack, leading to rejection.
2. Equivalence of Acceptance Criteria
A central result in automata theory is that the set of languages accepted by final state PDAs is the same as the set accepted by empty stack PDAs. We prove this by construction: providing an algorithm to convert a PDA of one type into an equivalent PDA of the other type.
The document Pushdown Automata 1 Formal Definition provides excellent, clear constructions for both directions of the proof.
Pushdown Automata 1 Formal Definition
We'll now study the two conversion algorithms that prove the equivalence of final-state and empty-stack PDAs.
Please read Section 2, 'Two Families' (pages 4-5), which contains Lemma 6. This section details the two constructions. Focus on the diagrams and the bullet points describing the new transitions added in each case.
Let's break down these two constructions.
Construction 1: From Empty Stack (N) to Final State (L)
Goal: Given a PDA that accepts by empty stack, construct a PDA that accepts the same language by final state.
Intuition: The new machine will simulate . But how can know when 's stack would have become empty? We give it a special "canary" symbol at the bottom of its stack. When sees this symbol, it knows 's stack is empty and can transition to a final state.
Algorithm:
- Create a new start state and a single new final state .
- Introduce a new bottom-of-stack symbol that is not in the original stack alphabet.
- Initialization: Add a transition from that does not read input. It pushes the original start symbol and the new marker onto the stack, then moves to the original start state .
δ'(q'_{in}, ε, □) = {(q_{in}, A_{in}□)}(Note: we assume the machine starts with□on the stack for this transition).
- Simulation: Copy all transitions from the original PDA to .
- Acceptance: For every state
qin the original PDA, add a transition to the new final stateq_f. This transition consumes no input and is only possible when the special marker is at the top of the stack.δ'(q, ε, □) = {(q_f, ε)}for allq ∈ Q_N.
This construction ensures that can only reach its final state precisely when would have emptied its stack.
Construction 2: From Final State (L) to Empty Stack (N)
Goal: Given a PDA that accepts by final state, construct a PDA that accepts the same language by empty stack.
Intuition: The new machine will simulate . Whenever has the option to enter a final state, we give a new option: jump to a special "stack-emptying" state. This state has a loop that will pop everything off the stack.
Algorithm:
- Create a new start state and a new "emptying" state . The new PDA will have no final states.
- Introduce a new bottom-of-stack symbol . This prevents the simulation from accidentally emptying the stack before acceptance.
- Initialization: Add a transition from that pushes the original start symbol and the new marker , then moves to the original start state .
δ'(q'_{in}, ε, □) = {(q_{in}, A_{in}□)}
- Simulation: Copy all transitions from the original PDA to .
- Emptying:
- For every final state
qin the original PDA , add anε-transition to the new emptying stateq_e. This transition pops nothing and pushes nothing (i.e., it leaves the stack top as is). This is the choice to accept.δ'(q, ε, A) = {(q_e, A)}for allq ∈ Fand for every stack symbolA.
- Add a loop on state
q_e. This loop will pop every symbol off the stack without reading input.δ'(q_e, ε, A) = {(q_e, ε)}for every stack symbolA(including the new marker ).
- For every final state
This allows the new PDA to nondeterministically decide to empty its stack whenever the original PDA would have reached an accepting state.
3. Applying the Conversion
Let's put the second construction into practice.
Test your understanding!
Consider the following PDA that accepts by final state (q2). Its language is strings with more a's than b's.

Apply the algorithm to transform this final-state PDA into an equivalent empty-stack PDA. Describe the new states and transitions you would add.
Show answer
Let's apply the Final State -> Empty Stack construction.
Original PDA (A_F):
- States:
- Final States:
- Stack Alphabet: (where
Xis the initial symbol)
New PDA (A_N):
-
New States: We add a new start state and a new emptying state .
- New set of states:
-
New Stack Symbol: We add a new bottom-of-stack marker, let's call it .
- New stack alphabet:
-
New Transitions:
-
Initialization: Add a transition from to :
δ(q'_{in}, ε, □) = {(q_0, X□)}
(This assumes we can define the PDA to start with on the stack. An alternative isδ(q'_{in}, ε, Z) = {(q_0, XZ)}for any initial stack symbol Z and then adjusting the transitions accordingly, but the new-marker approach is cleaner).
-
Simulation: All original transitions from the diagram are copied over. For example:
δ(q_0, a, X) = {(q_0, AX)}δ(q_0, b, A) = {(q_1, ε)}- ...and so on.
-
Emptying Trigger: Since
q2is the only final state, we addε-transitions fromq2toq_efor every possible symbol on top of the stack.δ(q_2, ε, A) = {(q_e, A)}δ(q_2, ε, B) = {(q_e, B)}δ(q_2, ε, X) = {(q_e, X)}δ(q_2, ε, □) = {(q_e, □)}
-
Emptying Loop: Add a universal pop loop on state
q_e.δ(q_e, ε, A) = {(q_e, ε)}δ(q_e, ε, B) = {(q_e, ε)}δ(q_e, ε, X) = {(q_e, ε)}δ(q_e, ε, □) = {(q_e, ε)}
-
The resulting PDA, , has no final states but will accept the exact same language by emptying its stack.
Conclusion
Today we've expanded our understanding of Pushdown Automata significantly. We have not only learned a new method of acceptance but have also formally proven that it is just as powerful as the one we already knew.
Key Takeaways:
- A PDA can accept a language by empty stack, which occurs when the entire input is consumed and the stack is left empty.
- We can design PDAs specifically for this criterion, often by ensuring the initial stack marker is popped as the final step.
- Acceptance by final state and acceptance by empty stack are equivalent. We proved this by providing two constructive algorithms:
- How to convert an empty-stack PDA to a final-state one.
- How to convert a final-state PDA to an empty-stack one.
Preview of the Next Lesson:
We have now established two equivalent formalisms for recognizing Context-Free Languages: PDAs that accept by final state, and PDAs that accept by empty stack. In the next lesson, we will complete the picture by formally connecting automata back to grammars. We will learn the algorithm to convert any Context-Free Grammar (CFG) into an equivalent PDA. This will demonstrate that PDAs are precisely the machines that recognize the languages generated by CFGs, solidifying the fundamental link between these two concepts.