Download - Lecture 18 - Pushdown Automata - Examples
Pushdown Automata - ExamplesLecture 18Section 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
1 Examples of PDAsEqual Number of a’s and b’sBalanced ParenthesesAlgebraic Expressions
2 Assignment
Robb T. Koether (Hampden-Sydney College) Pushdown Automata - Examples Mon, Oct 8, 2012 2 / 14
Outline
1 Examples of PDAsEqual Number of a’s and b’sBalanced ParenthesesAlgebraic Expressions
2 Assignment
Robb T. Koether (Hampden-Sydney College) Pushdown Automata - Examples Mon, Oct 8, 2012 3 / 14
Outline
1 Examples of PDAsEqual Number of a’s and b’sBalanced ParenthesesAlgebraic Expressions
2 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 a’s and b’s}.
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 a’s or b’s,on the stack.One state will represent an excess of a’s.Another state will represent an excess of b’s.We can tell when the excess switches from one symbol to theother 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)
b, $ → εa, ε → $
b, ε → $
a, ε → ab, a → ε
b, ε → ba, b → ε
a < b
a > b
a, $ → ε
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
1 Examples of PDAsEqual Number of a’s and b’sBalanced ParenthesesAlgebraic Expressions
2 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
1 Examples of PDAsEqual Number of a’s and b’sBalanced ParenthesesAlgebraic Expressions
2 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
1 Examples of PDAsEqual Number of a’s and b’sBalanced ParenthesesAlgebraic Expressions
2 Assignment
Robb T. Koether (Hampden-Sydney College) Pushdown Automata - Examples Mon, Oct 8, 2012 13 / 14
Assignment
AssignmentRead 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
{anbmcmdn | m, n ≥ 0}.
Design a PDA whose language is
{anbm | n 6= m}.
Robb T. Koether (Hampden-Sydney College) Pushdown Automata - Examples Mon, Oct 8, 2012 14 / 14