Languages and Finite Automata

Download Report

Transcript Languages and Finite Automata

Pushdown Automata
PDAs
Costas Busch - RPI
1
Pushdown Automaton -- PDA
Input String
Stack
States
Costas Busch - RPI
2
Initial Stack Symbol
stack
head
Stack
Stack
$
z
top
bottom
special symbol
Costas Busch - RPI
3
The States
Input
symbol
Pop
symbol
Push
symbol
a,
b

c
q1
q2
Costas Busch - RPI
4
q1
a, b  c
q2
input

a


a

stack
b
h
e
$
top
Replace
Costas Busch - RPI
c
h
e
$
5
q1
a,   c
q2
input

a


stack
b
h
e
$
top
Push
Costas Busch - RPI
a

c
b
h
e
$
6
q1
a, b  
q2
input

a


a

stack
b
h
e
$
top
Pop
Costas Busch - RPI
h
e
$
7
q1
a,   
q2
input

a


a

stack
b
h
e
$
top
No Change
Costas Busch - RPI
b
h
e
$
8
A Possible Transition
q1
input

stack
$
a
a, $  

top
q2

Pop
Costas Busch - RPI
a

empty
9
A Bad Transition
q1
input

a
a, b  c
q2

Empty stack
HALT
The automaton Halts in state
and Rejects the input string
Costas Busch - RPI
q1
10
A Bad Transition
q1
input

a
a,   c
q2

Empty stack
HALT
The automaton Halts in state
and Rejects the input string
Costas Busch - RPI
q1
11
No transition is allowed to be followed
When the stack is empty
q1
x, y  z
q2
Empty stack
Costas Busch - RPI
12
A Good Transition
q1
input

stack
$
a
a, $  b

top
q2

Pop
Costas Busch - RPI
a

b
13
Non-Determinism
a, b  c
q2
q1
q1
a, b  c
, b  c
q2
  transition
q3
These are allowed transitions in a
Non-deterministic PDA (NPDA)
Costas Busch - RPI
14
The input string aaabbb
is accepted by the NPDA:
a,   a
b, a  

,



b,
a



,
$

$
q3
q2
q0
q1
Costas Busch - RPI
26
NPDA example
NPDA
M
L( M )  {ww }
R
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
q2
28
Execution Example:
Time 0
Input
a b b a
$
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
29
Time 1
Input
a b b a
a,   a
b,   b
q0
,   
a
$
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
30
Time 2
Input
b
a
$
a b b a
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
31
Time 3
Input
a b b a
Guess the middle
of string
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
b
a
$
Stack
q2
32
Time 4
Input
b
a
$
a b b a
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
33
Time 5
Input
a b b a
a,   a
b,   b
q0
,   
a
$
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
34
Time 6
Input
a b b a
$
a,   a
b,   b
a, a  
b, b  
Stack
accept
q0
,   
q1
Costas Busch - RPI
, $  $
q2
35
Rejection Example:
Time 0
Input
a b b b
$
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
36
Time 1
Input
a b b b
a,   a
b,   b
q0
,   
a
$
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
37
Time 2
Input
b
a
$
a b b b
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
38
Time 3
Input
a b b b
Guess the middle
of string
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
b
a
$
Stack
q2
39
Time 4
Input
b
a
$
a b b b
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
40
Time 5
There is no possible transition.
Input
a b b b
a,   a
b,   b
q0
,   
Input is not
consumed
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
a
$
Stack
q2
41
Another computation on same string:
Input
Time 0
a b b b
$
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
42
Time 1
Input
a b b b
a,   a
b,   b
q0
,   
a
$
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
43
Time 2
Input
b
a
$
a b b b
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
44
Time 3
b
b
a
$
Input
a b b b
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
45
Time 4
b
b
b
a
$
Input
a b b b
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
Stack
q2
46
Time 5
Input
a b b b
a,   a
b,   b
q0
,   
No final state
is reached
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
b
b
b
a
$
Stack
q2
47
There is no computation
that accepts string abbb
abbb L(M )
a,   a
b,   b
q0
,   
a, a  
b, b  
q1
Costas Busch - RPI
, $  $
q2
48
A string is rejected if there is
no computation such that:
All the input is consumed
AND
The last state is a final state
At the end of the computation,
we do not care about the stack contents
Costas Busch - RPI
49
In other words, a string is rejected
if in every computation with this string:
The input cannot be consumed
OR
The input is consumed and the last
state is not a final state
OR
The stack head moves below the
bottom of the stack
Costas Busch - RPI
50
Pushing Strings
Input
symbol
Pop
symbol
Push
string
a,
b

w
q1
q2
Costas Busch - RPI
61
Example:
q1
a, b  cdf
q2
input
a
a
stack
b
h
e
$
top
Push
Costas Busch - RPI
c
d
f
h
e
$
pushed
string
62