prof. busch - lsu1 pushdown automata pdas. prof. busch - lsu2 pushdown automaton -- pda input string...

76
Prof. Busch - LSU 1 Pushdown Automata PDAs

Upload: phoebe-osborne

Post on 21-Dec-2015

231 views

Category:

Documents


1 download

TRANSCRIPT

Prof. Busch - LSU 1

Pushdown AutomataPDAs

Prof. Busch - LSU 2

Pushdown Automaton -- PDA

Input String

Stack

States

Prof. Busch - LSU 3

Initial Stack Symbol

Stack

$

Stack

z

bottomspecial symbol

stackhead

top

Appears at time 0

Prof. Busch - LSU 4

The States

q1 q2a, b c

Inputsymbol

Popsymbol

Pushsymbol

Prof. Busch - LSU 5

q1 q2a, b c

a

b top

input

stack

a

Replaceeh

$eh

$

c

Prof. Busch - LSU 6

q1 q2a, c

a a

Pushb

eh

$eh

$

bc

top

input

stack

Prof. Busch - LSU 7

q1 q2a, b

a a

Popb

eh

$eh

$

top

input

stack

Prof. Busch - LSU 8

q1 q2a,

a a

No Changeb

eh

$eh

$

btop

input

stack

Prof. Busch - LSU 9

Non-Determinism

q1

q2a, b c

q3a, b c

q1 q2, b c

transition

PDAs are non-deterministic

Allowed non-deterministic transitions

Prof. Busch - LSU 10

Example PDA

,

a, a

b, a q0 q1 q2 q3

b, a

, $ $

PDA : M }0:{)( nbaML nn

Prof. Busch - LSU 11

,

a, a

b, a q0 q1 q2 q3

b, a

, $ $

}0:{)( nbaML nn

Basic Idea:

1. Push the a’s on the stack

2. Match the b’s on input with a’s on stack

3. Match found

Prof. Busch - LSU 12

a, a

b, a 0q q1 q2 q3

Execution Example:

Input

a a a b b b

currentstate

b, a

Time 0

, , $ $

Stack

$

Prof. Busch - LSU 13

a, a

b, a q0 q1 q2 q3

Input

a a a b b b

b, a

Time 1

, , $ $

Stack

$

Prof. Busch - LSU 14

a, a

b, a q0 q1 q2 q3

Input

Stack

a a a b b b

$

a

b, a

Time 2

, , $ $

Prof. Busch - LSU 15

a, a

b, a q0 q1 q2 q3

Input

Stack

a a a b b b$

aa

b, a

Time 3

, , $ $

Prof. Busch - LSU 16

a, a

b, a q0 q1 q2 q3

Input

Stack

a a a b b b

$

aaa

b, a

Time 4

, , $ $

Prof. Busch - LSU 17

a, a

b, a q0 q1 q2 q3

Input

a a a b b b

Stack

$

aaa

b, a

Time 5

, , $ $

Prof. Busch - LSU 18

a, a

b, a q0 q1 q2 q3

Input

a a a b b b$

a

Stack

b, a

Time 6

, , $ $

a

Prof. Busch - LSU 19

a, a

b, a q0 q1 q2 q3

Input

a a a b b b$

Stack

b, a

Time 7

, , $ $

a

Prof. Busch - LSU 20

a, a

b, a q0 q1 q2 q3

Input

a a a b b b

b, a

Time 8

accept, , $ $

$

Stack

Prof. Busch - LSU 21

A string is accepted if there is a computation such that:

All the input is consumed AND The last state is an accepting state

we do not care about the stack contentsat the end of the accepting computation

Prof. Busch - LSU 22

0q

a, a

b, a q1 q2 q3

Rejection Example:

Input

a a b

currentstate

b, a

Time 0

, , $ $

Stack

$

Prof. Busch - LSU 23

0q

a, a

b, a q1 q2 q3

Rejection Example:

Input

a a b

currentstate

b, a

Time 1

, , $ $

Stack

$

Prof. Busch - LSU 24

0q

a, a

b, a q1 q2 q3

Rejection Example:

Input

a a b

currentstate

b, a

Time 2

, , $ $

Stack

$

a

Prof. Busch - LSU 25

0q

a, a

b, a q1 q2 q3

Rejection Example:

Input

a a b

currentstate

b, a

Time 3

, , $ $

Stack

$

aa

Prof. Busch - LSU 26

0q

a, a

b, a q1 q2 q3

Rejection Example:

Input

a a b

currentstate

b, a

Time 4

, , $ $

Stack

$

aa

Prof. Busch - LSU 27

0q

a, a

b, a q1 q2 q3

Rejection Example:

Input

a a b

currentstate

b, a

Time 4

, , $ $

Stack

$

aa

reject

Prof. Busch - LSU 28

The string is rejected by the PDAaab

a, a

b, a q0 q1 q2 q3

b, a

, , $ $

There is no accepting computation foraab

Prof. Busch - LSU 29

Another PDA example

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

PDA : M }},{:{)( bavvvML R

Prof. Busch - LSU 30

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

}},{:{)( bavvvML RBasic Idea:

1. Push v on stack

2. Guess middle of input

3. Match on input with v on stack

Rv

4. Match found

Prof. Busch - LSU 31

Execution Example:

Input

Time 0

Stack

$

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

a ab b

Prof. Busch - LSU 32

Input

a ab

Time 1

Stack

$

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

ab

Prof. Busch - LSU 33

Input

Time 2

Stack

$

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

aa ab b

b

Prof. Busch - LSU 34

Input

Time 3

Stack

$

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

aa ab b

b

Guess the middle of string

Prof. Busch - LSU 35

Input

Time 4

Stack

$

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

aa ab b

b

Prof. Busch - LSU 36

Input

Time 5

Stack

$

, $ $1q q2

bb

aa

,

,

, q0

bb

aa

,

,

a ab b a

Prof. Busch - LSU 37

Input

Time 6

Stack

$

, $ $q1

bb

aa

,

,

, q0

bb

aa

,

,

a ab b

accept

q2

Prof. Busch - LSU 38

Rejection Example:

Input

Time 0

Stack

$

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

a b b b

Prof. Busch - LSU 39

Input

Time 1

Stack

$

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

aa b b b

Prof. Busch - LSU 40

Input

Time 2

Stack

$

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

ab

a b b b

Prof. Busch - LSU 41

Input

Time 3

Stack

$

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

ab

Guess the middle of string

a b b b

Prof. Busch - LSU 42

Input

Time 4

Stack

$

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

ab

a b b b

Prof. Busch - LSU 43

Input

Time 5

Stack

$

, $ $1q q2

bb

aa

,

,

, q0

bb

aa

,

,

aa b b b

There is no possible transition.

Input is not consumed

Prof. Busch - LSU 44

Another computation on same string:

Input Time 0

Stack

$

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

a b b b

Prof. Busch - LSU 45

Input

Time 1

Stack

$

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

aa b b b

Prof. Busch - LSU 46

Input

Time 2

Stack

$

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

ab

a b b b

Prof. Busch - LSU 47

Input

Time 3

Stack

$ab

a b b b

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

b

Prof. Busch - LSU 48

Input

Time 4

Stack

a b b b

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

$abbb

Prof. Busch - LSU 49

Input

Time 5

Stack

a b b b

$abbb

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

No accept state is reached

Prof. Busch - LSU 50

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

There is no computation that accepts string abbb

)(MLabbb

Prof. Busch - LSU 51

Pushing & Popping Strings

q1 q221, wwa

Inputsymbol

Pushstring

Popstring

Prof. Busch - LSU 52

q1 q2cdfeba ,

a

btop

input

stack

a

Replacee

h he

cdf

pushstring

Example:

$ $

epopstring

top

Prof. Busch - LSU 53

q1 q2cdfeba ,

q1

q2

ea, b,

f,

,

d, c,

pop

push

Equivalent transitions

Prof. Busch - LSU 54

Another PDA example

$$, q1 q2

a, $ 0$a, 0 00a,1

b, $ 1$b, 1 11b, 0

PDA M

)}()(:},{{)( * wnwnbawML ba

Prof. Busch - LSU 55

Time 0

Input

a ab b b

currentstate

a

$

Stack

$$, q1 q2

a, $ 0$a, 0 00a,1

b, $ 1$b, 1 11b, 0

Execution Example:

Prof. Busch - LSU 56

Time 1

Input

a ab b b a

$

Stack

0

$$, q1 q2

a, $ 0$a, 0 00a,1

b, $ 1$b, 1 11b, 0

Prof. Busch - LSU 57

Time 3

Input

a bb b a

$

Stack

a

$

$$, q1 q2

a, $ 0$a, 0 00a,1

b, $ 1$b, 1 11b, 0

0

Prof. Busch - LSU 58

Time 4

Input

a bb b a

$

Stack

a

1

$$, q1 q2

a, $ 0$a, 0 00a,1

b, $ 1$b, 1 11b, 0

Prof. Busch - LSU 59

Time 5

Input

a bb b a

$

Stack

a

11

$$, q1 q2

a, $ 0$a, 0 00a,1

b, $ 1$b, 1 11b, 0

Prof. Busch - LSU 60

Time 6

Input

a bb b a

$

Stack

a

1

$$, q1 q2

a, $ 0$a, 0 00a,1

b, $ 1$b, 1 11b, 0

1

Prof. Busch - LSU 61

Time 7

Input

a bb b a

$

Stack

a

1

$$, q1 q2

a, $ 0$a, 0 00a,1

b, $ 1$b, 1 11b, 0

Prof. Busch - LSU 62

Time 8

Input

a bb b a a

$

Stack

$$, q1 q2

a, $ 0$a, 0 00a,1

b, $ 1$b, 1 11b, 0

accept

Prof. Busch - LSU 63

Formalities for PDAs

Prof. Busch - LSU 64

q1 q221, wwa

)},{(),,( 2211 wqwaq Transition function:

Prof. Busch - LSU 65

q1

q221, wwa

q331, wwa

)},(),,{(),,( 332211 wqwqwaq

Transition function:

Prof. Busch - LSU 66

Formal Definition

Pushdown Automaton (PDA)

),,,δ,Γ,Σ,( 0 FzqQM

States

Inputalphabet

Stackalphabet

Transitionfunction

Acceptstates

Stackstartsymbol

Initialstate

Prof. Busch - LSU 67

Instantaneous Description

),,( suq

Currentstate Remaining

input

Currentstackcontents

Prof. Busch - LSU 68

a, a

b, a q0 q1 q2 q3

Input

Stack

a a a b b b$

aa

b, a

Time 4:

, , $ $

Example: Instantaneous Description

$),,( 1 aaabbbq

a

Prof. Busch - LSU 69

a, a

b, a q0 q1 q2 q3

Input

Stack

a a a b b b$

aa

b, a

Time 5:

, , $ $

Example: Instantaneous Description

$),,( 2 aabbq

a

Prof. Busch - LSU 70

We write:

$),,($),,( 21 aabbqaaabbbq

Time 4 Time 5

Prof. Busch - LSU 71

a, a

b, a q0 q1 q2 q3

b, a

, , $ $

,$),(,$),($),,($),,(

$),,($),,($),,(

,$),(,$),(

3222

111

10

qqabqaabbq

aaabbbqaaabbbqaaabbbq

aaabbbqaaabbbq

A computation:

Prof. Busch - LSU 72

,$),(,$),($),,($),,(

$),,($),,($),,(

,$),(,$),(

3222

111

10

qqabqaabbq

aaabbbqaaabbbqaaabbbq

aaabbbqaaabbbq

For convenience we write:

,$),(,$),( 30 qaaabbbq

Prof. Busch - LSU 73

Language of PDA

Language accepted by PDA :M

)},,(),,(:{)( 0 sqzwqwML f

Initial state Accept state

)(ML

Prof. Busch - LSU 74

Example:,$),(,$),( 30 qaaabbbq

a, a

b, a q0 q1 q2 q3

b, a

, , $ $

PDA :M

)(MLaaabbb

Prof. Busch - LSU 75

,$),(,$),( 30 qbaq nn

a, a

b, a q0 q1 q2 q3

b, a

, , $ $

)(MLba nn

PDA :M

Prof. Busch - LSU 76

a, a

b, a q0 q1 q2 q3

b, a

, , $ $

PDA :M

}0:{)( nbaML nnTherefore: