Pushdown Automata PDAs - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Pushdown Automata PDAs

Description:

aaca, aaccaa, abccba, abcb, abba. Let PAL2 be the set of even length palindromes ... (qf, abba, Z) (q0, a, bbaZ) (qm, ba, baZ) (q0, l, abbaZ) (qm, a, bbaZ) (qm, ... – PowerPoint PPT presentation

Number of Views:522
Avg rating:3.0/5.0
Slides: 16
Provided by: erict9
Learn more at: http://www.cse.msu.edu
Category:
Tags: abba | automata | pdas | pushdown

less

Transcript and Presenter's Notes

Title: Pushdown Automata PDAs


1
Lecture 34
  • Pushdown Automata (PDAs)
  • Another example

2
Palindromes
  • Let PAL be the set of palindromes over a,b
  • Let PAL1 be the following related language
  • wcwr w consists only of as and bs
  • we add c to the input alphabet as a special
    marker character
  • Strings in PAL1
  • aca, bcb, abcba, aabcbaa, c
  • strings not in PAL1
  • aaca, aaccaa, abccba, abcb, abba
  • Let PAL2 be the set of even length palindromes
  • wwr w consists only of as and bs

3
PAL1
  • Lets first construct a PDA for PAL1
  • Basic ideas
  • Have one state remember first half of string
  • Have one state match second half of string to
    first half
  • Transition between these two states when the
    first c is encountered

4
PDA for PAL1
  • M (Q, S, G, q0, Z, A, d)
  • Q q0, qm, qf
  • S a, b, c
  • G Z, a, b
  • q0 q0
  • Z Z
  • A qf

5
Transition Function
Trans Current Input Top of Next Stack
State Char. Stack State
Update -------------------------------------------
------------ 1 q0 a
Z q0 aZ 2 q0
a a q0 aa 3 q0
a b q0 ab 4
q0 b Z q0
bZ 5 q0 b a
q0 ba 6 q0 b
b q0 bb 7 q0
c Z qm Z 8
q0 c a qm
a 9 q0 c b
qm b 10 qm a
a qm l 11 qm b
b qm l 12 qm
l Z qf Z
First three transitions push a on top of the
stack Second three transitions push b on the
stack Third three transitions switch state q0 to
qm No change to stack Transitions 10 and 11
match characters from first and last half of
input string
6
Notation comment
Trans Current Input Top of Next Stack
State Char. Stack State
Update -------------------------------------------
------------ 1 q0 a
Z q0 aZ 2 q0
a a q0 aa 3 q0
a b q0 ab 4
q0 b Z q0
bZ 5 q0 b a
q0 ba 6 q0 b
b q0 bb 7 q0
c Z qm Z 8
q0 c a qm
a 9 q0 c b
qm b 10 qm a
a qm l 11 qm b
b qm l 12 qm
l Z qf Z
  • We might represent transition 1 in two other ways
  • d(q0,a,Z) (q0, aZ)
  • (q0, a, Z, q0, aZ)
  • Question
  • Is this PDA deterministic?

7
Computation Graph 1
Trans Current Input Top of Next Stack
State Char. Stack State
Update -------------------------------------------
------------ 1 q0 a
Z q0 aZ 2 q0
a a q0 aa 3 q0
a b q0 ab 4
q0 b Z q0
bZ 5 q0 b a
q0 ba 6 q0 b
b q0 bb 7 q0
c Z qm Z 8
q0 c a qm
a 9 q0 c b
qm b 10 qm a
a qm l 11 qm b
b qm l 12 qm
l Z qf Z
(q0, abcba, Z)
8
Computation Graph 2
Trans Current Input Top of Next Stack
State Char. Stack State
Update -------------------------------------------
------------ 1 q0 a
Z q0 aZ 2 q0
a a q0 aa 3 q0
a b q0 ab 4
q0 b Z q0
bZ 5 q0 b a
q0 ba 6 q0 b
b q0 bb 7 q0
c Z qm Z 8
q0 c a qm
a 9 q0 c b
qm b 10 qm a
a qm l 11 qm b
b qm l 12 qm
l Z qf Z
(q0, abcab, Z)
9
Computation Graph 3
Trans Current Input Top of Next Stack
State Char. Stack State
Update -------------------------------------------
------------ 1 q0 a
Z q0 aZ 2 q0
a a q0 aa 3 q0
a b q0 ab 4
q0 b Z q0
bZ 5 q0 b a
q0 ba 6 q0 b
b q0 bb 7 q0
c Z qm Z 8
q0 c a qm
a 9 q0 c b
qm b 10 qm a
a qm l 11 qm b
b qm l 12 qm
l Z qf Z
(q0, acab, Z)
10
PAL2
  • Lets now construct a PDA for PAL
  • What is harder this time?
  • When do we switch from putting strings on the
    stack to matching?
  • Example
  • After seeing aab, should we switch to match mode
    or stay in stack mode?
  • Solution
  • Do both using nondeterminism

11
PDA for PAL2
  • M (Q, S, G, q0, Z, A, d)
  • Q q0, qm, qf
  • S a, b
  • G Z, a, b
  • q0 q0
  • Z Z
  • A qf

12
Transition Function
Trans Current Input Top of Next Stack
State Char. Stack State
Update -------------------------------------------
------------ 1 q0 a
Z q0 aZ 2 q0
a a q0 aa 3 q0
a b q0 ab 4
q0 b Z q0
bZ 5 q0 b a
q0 ba 6 q0 b
b q0 bb 7 q0
l Z qm Z 8
q0 l a qm
a 9 q0 l b
qm b 10 qm a
a qm l 11 qm b
b qm l 12 qm
l Z qf Z
First three transitions push a on top of the
stack Second three transitions push b on the
stack Third three transitions switch state q0 to
qm Note now that one of transitions 7, 8, and 9
can be used whenever transitions 1-6 are used.
13
Computation Graph 1
Trans Current Input Top of Next Stack
State Char. Stack State
Update -------------------------------------------
------------ 1 q0 a
Z q0 aZ 2 q0
a a q0 aa 3 q0
a b q0 ab 4
q0 b Z q0
bZ 5 q0 b a
q0 ba 6 q0 b
b q0 bb 7 q0
l Z qm Z 8
q0 l a qm
a 9 q0 l b
qm b 10 qm a
a qm l 11 qm b
b qm l 12 qm
l Z qf Z
(q0, abba, Z)
14
Computation Graph 2
Trans Current Input Top of Next Stack
State Char. Stack State
Update -------------------------------------------
------------ 1 q0 a
Z q0 aZ 2 q0
a a q0 aa 3 q0
a b q0 ab 4
q0 b Z q0
bZ 5 q0 b a
q0 ba 6 q0 b
b q0 bb 7 q0
l Z qm Z 8
q0 l a qm
a 9 q0 l b
qm b 10 qm a
a qm l 11 qm b
b qm l 12 qm
l Z qf Z
(q0, aba, Z)
15
PAL
  • Challenge
  • Construct a PDA for PAL
  • First step
  • Construct a PDA for odd length palindromes
  • Then
  • Combine PDAs for odd length and even length
    palindromes
Write a Comment
User Comments (0)
About PowerShow.com