Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Pushdown Automata - Examples

Lecture 18 Section 2.2 Robb T. Koether


Hampden-Sydney College

Mon, Oct 8, 2012

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

1 / 14

Outline

Examples of PDAs Equal Number of as and bs Balanced Parentheses Algebraic Expressions

Assignment

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

2 / 14

Outline

Examples of PDAs Equal Number of as and bs Balanced Parentheses Algebraic Expressions

Assignment

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

3 / 14

Outline

Examples of PDAs Equal Number of as and bs Balanced Parentheses Algebraic Expressions

Assignment

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

4 / 14

Examples

Example (Pushdown automaton)


Design a PDA that accepts the language {w | w contains an equal number of as and bs}.

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

5 / 14

Examples

Example (Pushdown automaton)


The strategy will be to keep the excess symbols, either as or bs, on the stack. One state will represent an excess of as. Another state will represent an excess of bs. We can tell when the excess switches from one symbol to the other because at that point the stack will be empty. In fact, when the stack is empty, we may return to the start state.

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

6 / 14

Examples
Example (Pushdown automaton)
a, a b, a
a>b

a, $

b, $

b, $

a, $

a<b

a, b b, b

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

7 / 14

Examples

Example (Pushdown automaton)


Note that this solution is inspired by the grammar S SS | aSb | bSa |

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

8 / 14

Outline

Examples of PDAs Equal Number of as and bs Balanced Parentheses Algebraic Expressions

Assignment

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

9 / 14

Examples

Example (Pushdown automata)


Let = {a, (, )}. Design a PDA whose language is {w | w contains balanced parentheses}.

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

10 / 14

Outline

Examples of PDAs Equal Number of as and bs Balanced Parentheses Algebraic Expressions

Assignment

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

11 / 14

Examples

Example (Pushdown automata)


Let = {a, b, c, +, , (, )}. Design a PDA whose language is {w | w is a valid algebraic expression}.

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

12 / 14

Outline

Examples of PDAs Equal Number of as and bs Balanced Parentheses Algebraic Expressions

Assignment

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

13 / 14

Assignment
Assignment
Read Section 2.2, pages 112 - 114. Problems 21, 22, 23, 24, page 130. Let = {a, (, ), [, ]}. Design a PDA whose language is {w | w contains balanced parentheses and brackets}. Design a PDA whose language is {an bm cm dn | m, n 0}. Design a PDA whose language is {an bm | n = m}.

Robb T. Koether (Hampden-Sydney College)

Pushdown Automata - Examples

Mon, Oct 8, 2012

14 / 14

You might also like