ACT CH4 Pushdown Automata
ACT CH4 Pushdown Automata
Regular Program
Stack Stack
stack
$ z top
head
Stack
States
6
The States
q1 a, b c q2
7
a, b c
q1 q2
input
a a
stack
b top Replac c
h e h
e e
$ $
8
a, c
q1 q2
input
a a
stack c
b top Pus
b
h h h
e e
$ $
9
a,
q1 q2
input
a a
stack
b top No b
h Change h
e e
$ $
10
a, b
q1 q2
input
a a
stack
b top
h Pop h
e e
$ $ 11
Pop from Empty Stack
a, b c
q1 q2
input
a
stack Pop Automaton halts!
top
12
Formal Definition
Pushdown Automaton (PDA) is described by 7-tuples
M (Q, Σ, Γ, δ, q0 , z , F ) Accept
states
States
Input Stack
alphabet Transition Initial start
Stack
function state symbol
alphabet
13
Transition function()
q0 , q1 b, a q2 , $ $ q3
18
(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 , ,$)
19
Rejection Example: Time 0
Input
a a b
$
Stack
current a, a b, a
state
q0 , q b, a q , $ $ q
1 2 3
20
Rejection Example: Time 1
Input
a a b
$
Stack
current a, a b, a
state
, q b, a q , $ $ q
q0 1 2 3
21
Rejection Example: Time 2
Input
a
a a b
$
Stack
current a, a b, a
state
q0 , q1 b, a q2 , $ $ q3
22
Rejection Example: Time 3
Input a
a
a a b
$
Stack
current a, a b, a
state
q0 , q1 b, a q2 , $ $ q3
23
Rejection Example: Time 4
Input a
a
a a b
$
Stack
current a, a b, a
state
q0 , q1 b, a q2 , $ $ q3
24
Rejection Example: Time 5
Input a
a
a a b
$
Stack
reject
current a, a b, a
state
q0 , q1 b, a q2 , $ $ q3
25
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
26
Another PDA example
PDA M: L( M ) {vv : v {a, b} }
R
a, a a, a
b, b b, b
q0
, q1 , $ $ q2
27
Basic Idea: L( M ) {vv : v {a, b} }
R
4. Match
a, a a, a
found
b, b b, b
q0 , q1 , $ $ q2
28
Execution Example: Time 0
Input
a b b a
$
Stack
a, a a, a
b, b b, b
q0 , q1 , $ $ q2
29
Time 1
Input
a b b a
a
$
Stack
a, a a, a
b, b b, b
q0 , q1 , $ $ q2
30
Time 2
Input
b
a b b a
a
$
Stack
a, a a, a
b, b b, b
q0 , q1 , $ $ q2
31
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
32
Time 4
Input
b
a b b a
a
$
Stack
a, a a, a
b, b b, b
q0 , q1 , $ $ q2
33
Time 5
Input
a b b a
a
$
Stack
a, a a, a
b, b b, b
q0 , q1 , $ $ q2
34
Time 6
Input
a b b a
$
Stack
a, a
a, a
b, b
b, b
accept
q0 , q1 , $ $ q2
35
Rejection Example: Time 0
Input
a b b b
$
Stack
a, a a, a
b, b b, b
q0 , q1 , $ $ q2
36
Time 1
Input
a b b b
a
$
Stack
a, a a, a
b, b b, b
q0 , q1 , $ $ q2
37
Time 2
Input
b
a b b b
a
$
Stack
a, a a, a
b, b b, b
q0 , q1 , $ $ q2
38
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
39
Time 4
Input
b
a b b b
a
$
Stack
a, a a, a
b, b b, b
q0 , q1 , $ $ q2
40
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
q0 , q1 , $ $ q2
41
There is no computation
that accepts string abbb
abbb L(M )
a, a a, a
b, b b, b
q0 , q1 , $ $ q2
42
Language of PDA
43
Construction of PDA
• Examle 1 : Design a PDA that accepts the language L = {a nb n | n ≥ 0}
Solution:
• Every time ‘a’ comes before ‘b’. When ‘a’ comes then push it in stack and if again
‘a’ comes then also push it.
• After that, when ‘b’ comes then pop one ‘a’ from the stack each time.
• So, at the end if the stack becomes empty then we can say that the string is
accepted by the PDA.
The language accepted by DPDA is a subset of the The language accepted by NPDA is not
3. language accepted by NDPA. a subset of the language accepted by
DPDA.
• We can prove that PDAs accept exactly the context free languages by showing
that we can convert any CFG into a PDA and any PDA into a CFG