Pushdown Automata (PDA) Examples with Solutions

Pushdown Automata (PDA) Examples with Solutions

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.

  1. Design a PDA for L = {aⁿbⁿcᵐ | n,m ≥ 1}.
  2. Construct a PDA that accepts 0ⁿ1ⁿ2ᵐ.
  3. Design a PDA for balanced braces { }.
  4. Construct a PDA that accepts palindromes over {0,1}.
  5. 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.

★
★
★
★
★
Votes: 0
E-mail me when people leave their comments –

Scott is a Marketing Consultant and Writer. He has 10+ years of experience in Digital Marketing. If you need more information please contact on readdive@gmail.com.

You need to be a member of CISO Platform to add comments!

Join CISO Platform

Join The Community Discussion

CISO Platform

A global community of 6K+ Senior IT Security executives and 40K+ subscribers with the vision of meaningful collaboration, knowledge, and intelligence sharing to fight the growing cyber security threats.

Join CISO Community Share Your Knowledge (Post A Blog)
 

 

 

Turbo Talks: Safe AI Agents — Guardrails, Scope Enforcement and Governance

  • Description:

    Turbo Talks is a free 20-minute live session series on agentic AI pentesting and AI safety for security leaders, hosted by CISO Platform. Technology partner: FireCompass.

    Speaker: Bikash Barai, Founder & CEO, FireCompass

    As offensive AI agents get more capable, control becomes the harder problem. Practical guardrails and governance for deploying them safely.

    Time: 11:30 AM ET / 7:30 PM GST / 9:00 PM IST ·…

  • Created by: Priyanka Aash
  • Tags: turbo talks, agentic ai, ai safety

CISOPlatform Breakfast Mumbai: Offensive Security for CISOs

  • Description:

    Theme: Offensive Security for CISOs — Validating Exposure at Attacker Speed

    A closed-door breakfast for CISOs and heads of security. Peer discussion under the Chatham House rule, not a product presentation.

    What the table will work through

    1. Exploit windows in days, not months. Edge devices, CI/CD and AI gateways were all exploited within weeks of disclosure this autumn (GitLab CVE-2026-97229, Cisco ASA/FTD…
  • Created by: Priyanka Aash
  • Tags: ciso breakfast, mumbai, offensive security, pentesting

CISOPlatform Dinner Delhi: Red Team Stories and 2027 Priorities

  • Description:

    Theme: Red Team Stories and Offensive Security Priorities for 2027

    An invite-only dinner for CISOs and security leaders in Delhi. Informal peer conversation under the Chatham House rule.

    Conversation starters

    • What did attackers (or your red team) find first in your environment, and what did you change after?
    • AI agents on both sides: attackers automating exploitation, and defenders using agents to pentest.
    • Your top…
  • Created by: Priyanka Aash
  • Tags: ciso dinner, delhi, offensive security, red teaming

CISOPlatform Dinner Delhi: Red Team Stories and 2027 Priorities

  • Description:

    Theme: Red Team Stories and Offensive Security Priorities for 2027

    An invite-only dinner for CISOs and security leaders in Delhi. Informal peer conversation under the Chatham House rule.

    Conversation starters

    • What did attackers (or your red team) find first in your environment, and what did you change after?
    • AI agents on both sides: attackers automating exploitation, and defenders using agents to pentest.
    • Your top…
  • Created by: Priyanka Aash
  • Tags: ciso dinner, delhi, offensive security, red teaming