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

Lec. 06 Pushdown Automata

TOA

Uploaded by

mehwishmoosa2003
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Lec. 06 Pushdown Automata

TOA

Uploaded by

mehwishmoosa2003
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 82

Pushdown Automata

PDAs

Lecture: 12
Friday, 20th Sept 2024

1
Pushdown Automaton -- PDA

Pushdown automata
are used in theories
about what can be
computed by machines.
They are more capable
than finite-state
machines but less
capable than Turing
machines.

2
Pushdown Automaton -- PDA
Input Tape/String

Stack
tape head

Finite Control/States

stack head

Accept/Reject
3
Input Tape/String

a l p h a b e t

The input tape is divided into finitely


many cells. Each cell contains a
symbol in an alphabet Σ.
Input Tape/String
a

The head scans at a cell on the tape


and can read a symbol on the cell. In
each move, the head can move to
the right cell.
The stack head always scans the top
symbol of the stack. It performs two
basic operations:

Push: add a new symbol at the top.


Pop: read and remove the top symbol.
Stack
Alphabet of stack symbols: Γ
Initial Stack Symbol

Stack Stack

stack
top
head

bottomspecial symbol
Appears at time 0
7
The finite control has finitely many
states which form a set Q. For each
move, the state is changed according
to the evaluation of a transition
Q x (Γ U {ε})
function
δ : Q x (Σ U {ε}) x (Γ U {ε}) → 2 .
The States

Input Pop Push


symbol symbol symbol

9
input
   

stack
top Replac
c
e
$ $
10
input
   

stack c
top Pus
h
$ $
11
input
   

stack
top
Pop

$ $
12
input
   

stack
top No b
Change
$ $
13
Pop from Empty Stack
a, b  c

input
 
stack Pop Automaton halts!

top

If the automaton attempts to pop from


empty stack then it halts and rejects input

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

  transition

15
Example PDA

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

16
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
found

17
Execution Example: Time 0
Input

Stack

current
state

q0
18
Time 1
Input

Stack

19
Time 2
Input

Stack

20
Time 3
Input

Stack

21
Time 4
Input

Stack

22
Time 5
Input

Stack

23
Time 6
Input

Stack

24
Time 7
Input

Stack

25
Time 8
Input

Stack

accept

26
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
27
Rejection Example: Time 0
Input

Stack

current
state

q0
28
Rejection Example: Time 1
Input

Stack

current
state

q0
29
Rejection Example: Time 2
Input

Stack

current
state

q0
30
Rejection Example: Time 3
Input

Stack

current
state

q0
31
Rejection Example: Time 4
Input

Stack

current
state

q0
32
Rejection Example: Time 4
Input

Stack
reject
current
state

q0
33
There is no accepting computation foraab

The string aab is rejected by the PDA

34
Another PDA example

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

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

35
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

36
Execution Example: Time 0
Input

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

37
Time 1
Input

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

38
Time 2
Input

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

39
Time 3
Input

Guess the middle


of string
Stack
a,   a a, a  
b,   b b, b  

40
Time 4
Input

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

41
Time 5
Input

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

q1
42
Time 6
Input

Stack
a,   a a, a  
b,   b b, b  
accept

43
Rejection Example: Time 0
Input

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

44
Time 1
Input

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

45
Time 2
Input

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

46
Time 3
Input

Guess the middle


of string
Stack
a,   a a, a  
b,   b b, b  

47
Time 4
Input

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

48
Time 5
Input There is no possible
transition.
Input is not
consumed

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

q1
49
Another computation on same string:
Input Time 0

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

50
Time 1
Input

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

51
Time 2
Input

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

52
Time 3
Input

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

53
Time 4
Input

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

54
Time 5
Input
No accept state
is reached

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

55
There is no computation
that accepts string abbb

abbb  L(M )

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

56
Pushing & Popping Strings

Input Pop Push


symbol string string

a, w1  w2

57
Example: a, eb  cdf

input

stack
top push
pop top string
string Repla
ce
$ $
58
a, eb  cdf

Equivalent
transitions
pop
a, e   a, b  

,   
push
a,   f a,   d a,   c

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

, $  $
60
Execution Example: Time 0
Input

Stack

current
state , $  $
61
Time 1
Input

Stack

, $  $
62
Time 3
Input

Stack

, $  $
63
Time 4
Input

Stack

, $  $
64
Time 5
Input

Stack

, $  $
65
Time 6
Input

Stack

, $  $
66
Time 7
Input

Stack

, $  $
67
Time 8
Input

Stack

accept
, $  $
68
Formalities for PDAs

69
a, w1  w2

Transition function:
 (q1, a,w1)  {(q2,w2 )}

70
a, w1  w2

a, w1  w3

Transition function:

 (q1, a,w1)  {(q2,w2 ), (q3,w3 )}

71
Formal Definition
Pushdown Automaton (PDA)

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

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

( q, u , s )

Current Current
state Remaining stack
input contents

73
Example: Instantaneous Description
(q1, bbb, aaa$)

Time 4: Input

Stack

74
Example: Instantaneous Description
(q2 , bb, aa$)

Time 5: Input

Stack

75
We write:

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


Time 4 Time 5

76
A computation:

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


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

77
(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 ,  ,$)

78
Language of PDA

Language L(M ) accepted by PDAM :


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

Initial state Accept state

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

aaabbb  L(M )

PDA M :

80

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

n n
a b  L(M )

PDA M :

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

PDA M :

82

You might also like