# Pushdown Automata: Examples

Last modified: Jul 23, 2019

Abstract

Practice running and constructing PDAs.

# 1 JFLAP

1. Review the Pushdown Automata section of the Tutorial.

• When you create a new PDA, JFlap give you an option to allow multiple or single (only) character input.

• The single character input option also limits JFlap to pushing at most one character onto the stack per transition.
• Our definition of PDAs (from the textbook) allows only single input characters, but allows multiple symbols to be pushed onto the stack in one transition.

• To get this in JFlap, select “Multiple Character Input” but remember that you must only transition on one input character at a time.

2. Here is the PDA for $0^n1^n$.

Try executing it (“Input -> Step by Closure”) on these inputs:

• 0
• 1
• 01
• 10
• 0011
• 000111
• 00110
3. Here is the PDA for $ww^R$.

Try executing it (“Input -> Step by Closure”) on these inputs:

• 0
• 1
• 00
• 0101
• 0110
• 10101
• 011001
• 01100110
4. A palindrome is a string that reads the same backwards as forwards. All strings in our $ww^R$ language are palindromes. But “1001001” is also a palindrome, and is not in $ww^R$.

Can you modify the $ww^R$ PDA so that it recognizes all palindromes over $\{0, 1\}^*$? (This is a good way to see if you have really embraced thinking about non-determinism.)

Try it before looking at the answer.

# 2 Sample Problems

Think of a PDA as an NFA “controller” coupled to a stack.

Let’s start with a problem where we don’t even need the stack.

## 2.1 A PDA can do anything a FA can.

1. Design a PDA to recognize the set of all strings over ${0, 1}$ that contain 101.
Reveal

## 2.2 PDAs are good at counting.

Sometimes, though, the stack can actually help. For example, PDAs are very good at counting things.

Consider the problem of designing an automaton to recognize strings with k occurrences of 101, where k is some constant.

1. Design a PDA to recognize the set of all strings over ${0, 1}$ that contain exactly three non-overlapping occurrences of 101.

Reveal

This PDA would be very easily modified to look for two occurrences of 101, or five, or 100. Much easier than modifying the NFA.

2. How would you modify the previous answer to accept strings with 5 occurrences of 101?

Reveal

## 2.3 PDAs are good at matching.

Another thing that PDAs are good at is matching/nesting combinations.

For example, consider the use of parentheses and brackets in C++ array expressions,

a[2*(i+1)] = (b[i] - 1)

1. Design a PDA to determine if the parentheses and brackets in such expressions are properly matched and nested.
Reveal