Pushdown Automata (PDA) is an important topic in the Theory of Automata (TOC). Unlike a Finite Automaton (FA), a PDA uses a stack as additional memory, allowing it to recognize Context-Free Languages (CFLs). Learning PDA examples with solutions helps students understand stack operations and solve university exam questions more easily.
In this article, you will learn several Pushdown Automata examples with step-by-step solutions, transition functions, stack operations, and accepted strings.
What is a Pushdown Automaton (PDA)?
A Pushdown Automaton (PDA) is a finite automaton equipped with a stack. It reads an input string one symbol at a time and performs push, pop, or no operation on the stack based on the current state and input symbol.
A PDA is more powerful than a DFA or NFA because it can recognize Context-Free Languages (CFLs).
Components of a PDA
A Pushdown Automaton consists of:
- A finite set of states (Q)
- Input alphabet (Σ)
- Stack alphabet (Γ)
- Transition function (δ)
- Start state (q₀)
- Initial stack symbol (Z₀)
- Final states (F)
Example 1: PDA for Language L = {aⁿbⁿ | n ≥ 1}
Problem
Design a PDA that accepts all strings having an equal number of a's followed by b's.
Examples
Accepted Strings
- ab
- aabb
- aaabbb
- aaaabbbb
Rejected Strings
- aab
- abb
- abab
- aaabb
Solution
Idea
- Push one symbol (A) onto the stack for every a.
- Pop one A for every b.
- Accept if the input ends and only the bottom stack symbol remains.
States
- q0 → Start state
- q1 → Reading a's
- q2 → Reading b's
- qf → Final state
Transition Table
Current State | Input | Stack Top | Operation | Next State |
q0 | ε | Z | Push Z | q1 |
q1 | a | Z | Push A | q1 |
q1 | a | A | Push A | q1 |
q1 | b | A | Pop A | q2 |
q2 | b | A | Pop A | q2 |
q2 | ε | Z | Accept | qf |
Working Example
Input: aabb
Input | Stack |
ε | Z |
a | AZ |
aa | AAZ |
aab | AZ |
aabb | Z |
Since the stack returns to Z after the input is consumed, the string is accepted.
Example 2: PDA for Balanced Parentheses
Problem
Design a PDA that accepts balanced parentheses.
Examples
Accepted Strings
- ()
- (())
- (()())
- ((()))
Rejected Strings
- (()
- ())
- ))((
- (((
Solution
Idea
- Push ( onto the stack whenever an opening parenthesis is read.
- Pop ( whenever a closing parenthesis is read.
- Accept if the stack becomes empty after reading the complete input.
Transition Table
Current State | Input | Stack Top | Operation |
q0 | ( | Z | Push ( |
q0 | ( | ( | Push ( |
q0 | ) | ( | Pop |
q0 | ε | Z | Accept |
Example 3: PDA for Palindrome Language
Problem
Design a PDA that accepts strings of the form:
L = {wwᴿ | w ∈ {a,b}*}
Examples
Accepted Strings
- aa
- abba
- baab
- abccba (if alphabet includes c)
Solution
Idea
- Push symbols while reading the first half.
- Guess the middle using an ε-transition.
- Pop matching symbols while reading the second half.
- Accept when the stack becomes empty.
Example 4: PDA for Language L = {0ⁿ1ⁿ | n ≥ 1}
Problem
Construct a PDA that accepts equal numbers of 0's followed by 1's.
Examples
Accepted Strings
- 01
- 0011
- 000111
Rejected Strings
- 001
- 011
- 0101
Solution
Stack Operations
- Push X for every 0.
- Pop X for every 1.
- Accept when the input finishes and only the bottom marker remains.
Transition Table
Current State | Input | Stack Top | Operation |
q0 | 0 | Z | Push X |
q0 | 0 | X | Push X |
q0 | 1 | X | Pop |
q1 | 1 | X | Pop |
q1 | ε | Z | Accept |
Example 5: PDA Accepting by Empty Stack
Problem
Construct a PDA that accepts L = {aⁿbⁿ} using the empty stack method.
Solution
Procedure
- Push one stack symbol for each a.
- Pop one symbol for each b.
- Accept when both:
- The input is completely read.
- The stack becomes empty.
This PDA accepts by empty stack instead of reaching a final state.
Tips for Solving PDA Problems
- Identify the language pattern before designing the PDA.
- Determine where symbols should be pushed onto the stack.
- Decide when symbols should be popped.
- Ensure every pushed symbol has a matching pop operation.
- Test the PDA using both accepted and rejected strings.
Common Mistakes
- Forgetting the initial stack symbol.
- Popping symbols before they are pushed.
- Allowing b before all a's are processed in languages like aⁿbⁿ.
- Accepting before the stack is empty (when using empty stack acceptance).
- Confusing acceptance by final state with acceptance by empty stack.
Practice Questions
Try solving the following PDA problems.
- Design a PDA for L = {aⁿbⁿcᵐ | n,m ≥ 1}.
- Construct a PDA that accepts 0ⁿ1ⁿ2ᵐ.
- Design a PDA for balanced braces { }.
- Construct a PDA that accepts palindromes over {0,1}.
- Design a PDA for L = {wcwᴿ | w ∈ {a,b}*}.
Frequently Asked Questions (FAQs)
What is a Pushdown Automaton (PDA)?
A Pushdown Automaton (PDA) is a finite automaton with an additional stack memory that recognizes Context-Free Languages (CFLs).
Why does a PDA use a stack?
The stack allows a PDA to remember previously read symbols, enabling it to recognize languages such as aⁿbⁿ, balanced parentheses, and palindromes.
What is the difference between a DFA and a PDA?
A DFA has no memory other than its current state, whereas a PDA uses a stack to store and retrieve symbols, making it more powerful.
How can a PDA accept a string?
A PDA can accept a string in two ways:
- By reaching a final state.
- By emptying the stack after processing the entire input.
Which languages can a PDA recognize?
A PDA recognizes Context-Free Languages (CFLs), which cannot generally be recognized by finite automata.
Conclusion
Practicing PDA examples with solutions helps students understand how stack operations are used to recognize Context-Free Languages. By solving examples such as aⁿbⁿ, 0ⁿ1ⁿ, balanced parentheses, and palindromes, you can develop a strong understanding of Pushdown Automata and confidently solve Theory of Computation questions in university exams and competitive tests.

Comments