Lec. 06 Pushdown Automata
Lec. 06 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
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
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
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:
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:
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
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} }
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
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
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
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:
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:
76
A computation:
77
(q0 , aaabbb,$) (q1, aaabbb,$)
(q1, aabbb, a$) (q1, abbb, aa$) (q1, bbb, aaa$)
(q2 , bb, aa$) (q2 , b, a$) (q2 , ,$) (q3 , ,$)
(q0 , aaabbb,$) (q3 , ,$)
78
Language of PDA
L(M ) {w : (q0 ,w, z ) (qf , , s )}
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