0% found this document useful (0 votes)
31 views

8 Pda

The document describes pushdown automata (PDAs). PDAs are finite state machines that have an additional stack. They contain states, input symbols, transitions between states that can pop/push symbols from the stack, and an initial and final stack symbol. Transitions are defined by the current state, input symbol, top of stack symbol to pop (if any), and symbol to push (if any). PDAs can accept or reject strings by reaching an accepting state with an empty stack after reading the entire input string. They are non-deterministic and can have multiple transitions from a state on the same input/stack symbols. Examples are given of PDAs that accept specific languages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

8 Pda

The document describes pushdown automata (PDAs). PDAs are finite state machines that have an additional stack. They contain states, input symbols, transitions between states that can pop/push symbols from the stack, and an initial and final stack symbol. Transitions are defined by the current state, input symbol, top of stack symbol to pop (if any), and symbol to push (if any). PDAs can accept or reject strings by reaching an accepting state with an empty stack after reading the entire input string. They are non-deterministic and can have multiple transitions from a state on the same input/stack symbols. Examples are given of PDAs that accept specific languages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 77

Pushdown Automata

PDAs

1
Pushdown Automaton -- PDA
Input String

Stack

States

2
Initial Stack Symbol

Stack Stack

stack
$ z top
head

bottom special symbol


Appears at time 0
3
The States

Input Pop Push


symbol symbol symbol

a, b  c
q1 q2

4
a, b  c
q1 q2

input
 a   a 

stack
b top c
h Replace h
e e
$ $
5
a,   c
q1 q2

input
 a   a 

stack c
b top b
h Push h
e e
$ $
6
a, b  
q1 q2

input
 a   a 

stack
b top
h Pop h
e e
$ $
7
a,   
q1 q2

input
 a   a 

stack
b top b
h No Change h
e e
$ $
8
Pop from Empty Stack
a, b  c
q1 q2
input
 a 
stack Pop Automaton halts!

top

If the automaton attempts to pop from


empty stack then it halts and rejects input

9
Non-Determinism
PDAs are non-deterministic
Allowed non-deterministic transitions

q2
a, b  c
, b  c
q1 q1 q2

a, b  c
  transition
q3
10
Example PDA

n n
PDA M: L( M )  {a b : n  0}

a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
11
n n
L( M )  {a b : n  0}
Basic Idea:

Push the a’s 2. Match the b’s on input


on the stack with a’s on stack

3. Match
a,   a b, a   found

q0  ,    q1 b, a   q2  , $  $ q3
12
Execution Example: Time 0
Input
a a a b b b
$
Stack

current a,   a b, a  
state

q0  ,    q b, a   q  , $  $ q
1 2 3
13
Time 1
Input
a a a b b b
$
Stack

a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
14
Time 2
Input
a a a b b b a
$
Stack

a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
15
Time 3
Input a
a a a b b b a
$
Stack

a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
16
Time 4
a
Input
a
a a a b b b a
$
Stack

a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
17
Time 5
a
Input
a
a a a b b b a
$
Stack

a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
18
Time 6
Input a
a a a b b b a
$
Stack

a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
19
Time 7
Input
a a a b b b a
$
Stack

a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
20
Time 8
Input
a a a b b b
$
Stack

a,   a b, a  
accept
q0  ,    q1 b, a   q2  , $  $ q3
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 contents


at the end of the accepting computation
22
Rejection Example: Time 0
Input
a a b
$
Stack

current a,   a b, a  
state

q0  ,    q b, a   q  , $  $ q
1 2 3
23
Rejection Example: Time 1
Input
a a b
$
Stack

current a,   a b, a  
state

q0  ,    q1 b, a   q2  , $  $ q3
24
Rejection Example: Time 2
Input
a
a a b
$
Stack

current a,   a b, a  
state

q0  ,    q1 b, a   q2  , $  $ q3
25
Rejection Example: Time 3
Input a
a
a a b
$
Stack

current a,   a b, a  
state

q0  ,    q1 b, a   q2  , $  $ q3
26
Rejection Example: Time 4
Input a
a
a a b
$
Stack

current a,   a b, a  
state

q0  ,    q1 b, a   q2  , $  $ q3
27
Rejection Example: Time 4
Input a
a
a a b
$
Stack
reject
current a,   a b, a  
state

q0  ,    q1 b, a   q2  , $  $ q3
28
There is no accepting computation for aab
The string aab is rejected by the PDA

a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
29
Another PDA example

R 
PDA M: L( M )  {vv : v  {a, b} }

a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
30
R 
Basic Idea: L( M )  {vv : v  {a, b} }

Push v 3. Match v R on input


2. Guess
on stack with v on stack
middle
of input
a,   a a, a   4. Match
b,   b b, b   found

q0 ,    q1 , $  $ q2
31
Execution Example: Time 0
Input
a b b a
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
32
Time 1
Input
a b b a
a
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
33
Time 2
Input
b
a b b a
a
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
34
Time 3
Input
b
a b b a
Guess the middle a
of string $
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
35
Time 4
Input
b
a b b a
a
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
36
Time 5
Input
a b b a
a
$
Stack
a,   a a, a  
b,   b b, b  

,    , $  $ q2
q0 q1
37
Time 6
Input
a b b a
$
Stack
a,   a a, a  
b,   b b, b  
accept
q0 ,    q1 , $  $ q2
38
Rejection Example: Time 0
Input
a b b b
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
39
Time 1
Input
a b b b
a
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
40
Time 2
Input
b
a b b b
a
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
41
Time 3
Input
b
a b b b
Guess the middle a
of string $
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
42
Time 4
Input
b
a b b b
a
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
43
Time 5
Input There is no possible transition.

a b b b Input is not a
consumed
$
Stack
a,   a a, a  
b,   b b, b  

,    , $  $ q2
q0 q1
44
Another computation on same string:
Input Time 0
a b b b
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
45
Time 1
Input
a b b b
a
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
46
Time 2
Input
b
a b b b
a
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
47
Time 3
Input b
b
a b b b
a
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
48
Time 4 b
Input b
b
a b b b
a
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
49
Time 5 b
Input b
No accept state b
a b b b is reached a
$
Stack
a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
50
There is no computation
that accepts string abbb

abbb  L(M )

a,   a a, a  
b,   b b, b  

q0 ,    q1 , $  $ q2
51
Pushing & Popping Strings

Input Pop Push


symbol string string

a , w1  w2
q1 q2

52
Example: a , eb  cdf
q1 q2

input

 a 
 
 a 

stack
top c push
e top d
pop string
b f
string h Replace h
e e
$ $
53
a , eb  cdf
q1 q2

Equivalent
transitions
pop
a, e   a, b  
q1
,   
push
a,   f a,   d a,   c q
2

54
Another PDA example
*
L( M )  {w  {a, b} : na ( w)  nb ( w)}
PDA M

a, $  0$ b, $  1$
a, 0  00 b, 1  11
a, 1   b, 0  

q1 , $  $ q2
55
Execution Example: Time 0
Input
a b b b a a

$
a, $  0$ b, $  1$
Stack
a, 0  00 b, 1  11
a, 1   b, 0  
current
state
q1 , $  $ q2
56
Time 1
Input
a b b b a a
0
$
a, $  0$ b, $  1$
Stack
a, 0  00 b, 1  11
a, 1   b, 0  

q1 , $  $ q2
57
Time 3
Input
a b b b a a
0
$
a, $  0$ b, $  1$
Stack
a, 0  00 b, 1  11
a, 1   b, 0  

q1 , $  $ q2
58
Time 4
Input
a b b b a a
1
$
a, $  0$ b, $  1$
Stack
a, 0  00 b, 1  11
a, 1   b, 0  

q1 , $  $ q2
59
Time 5
Input
a b b b a a 1
1
$
a, $  0$ b, $  1$
Stack
a, 0  00 b, 1  11
a, 1   b, 0  

q1 , $  $ q2
60
Time 6
Input
a b b b a a 1
1
$
a, $  0$ b, $  1$
Stack
a, 0  00 b, 1  11
a, 1   b, 0  

q1 , $  $ q2
61
Time 7
Input
a b b b a a
1
$
a, $  0$ b, $  1$
Stack
a, 0  00 b, 1  11
a, 1   b, 0  

q1 , $  $ q2
62
Time 8
Input
a b b b a a

$
a, $  0$ b, $  1$
Stack
a, 0  00 b, 1  11
a, 1   b, 0  
accept
q1 , $  $ q2
63
Formalities for PDAs

64
a , w1  w2
q1 q2

Transition function:
 (q1 , a ,w 1 )  {(q2 ,w 2 )}

65
a , w1  w2 q2

q1

a , w1  w3 q3

Transition function:

 (q1 , a ,w 1 )  {(q2 ,w 2 ), (q3 ,w 3 )}

66
Formal Definition
Pushdown Automaton (PDA)

M  (Q, Σ, Γ, δ, q0 , z , F ) Accept
states
States

Input Stack
alphabet Transition Initial start
Stack
function state symbol
alphabet
67
Instantaneous Description

( q, u , s )

Current Current
Remaining
state stack
input
contents

68
Example: Instantaneous Description
(q1, bbb, aaa$)
a
Time 4: Input a
a a a b b b a
$
Stack
a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
69
Example: Instantaneous Description
(q2 , bb, aa$)
a
Time 5: Input a
a a a b b b a
$
Stack
a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
70
We write:

(q1, bbb, aaa$)  (q2 , bb, aa$)


Time 4 Time 5

71
A computation:

(q0 , aaabbb,$) (q1, aaabbb,$) 


(q1, aabbb, a$) (q1, abbb, aa$) (q1, bbb, aaa$) 
(q2 , bb, aa$) (q2 , b, a$) (q2 ,  ,$) (q3 ,  ,$)

a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
72
(q0 , aaabbb,$) (q1, aaabbb,$) 
(q1, aabbb, a$) (q1, abbb, aa$) (q1, bbb, aaa$) 
(q2 , bb, aa$) (q2 , b, a$) (q2 ,  ,$) (q3 ,  ,$)

For convenience we write:


(q0 , aaabbb,$)  ( q3 ,  ,$)

73
Language of PDA

Language L(M ) accepted by PDA M :


L(M )  {w : (q0 ,w , z )  (qf , , s )}

Initial state Accept state

74
Example: 
(q0 , aaabbb,$)  (q3 ,  ,$)

aaabbb  L(M )

PDA M :

a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
75

n n
(q0 , a b ,$)  (q3 ,  ,$)

n n
a b  L(M )

PDA M :

a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
76
n n
Therefore: L( M )  {a b : n  0}

PDA M :

a,   a b, a  

q0  ,    q1 b, a   q2  , $  $ q3
77

You might also like