NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition....
-
Upload
nguyenhuong -
Category
Documents
-
view
221 -
download
3
Transcript of NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition....
![Page 1: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/1.jpg)
1
… NPDAs continued
![Page 2: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/2.jpg)
2
Pushing Strings
q1 q2a, bw
Input
symbol
Pop
symbolPush
string
![Page 3: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/3.jpg)
3
q1 q2a, bcdf
a
b top
input
stack
a
Push
eh h
e
cdf
pushed
string
Example:
$ $
![Page 4: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/4.jpg)
4
Another NPDA example
$$, q1 q2
a, $0$
a, 000a,1
b, $1$
b,111b, 0
NPDA M
}:{)( ba nnwML
![Page 5: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/5.jpg)
5
Time 0
Input
a ab b b
current
state
a
$
Stack
$$, q1 q2
a, $0$
a, 000a,1
b, $1$
b,111b, 0
Execution Example:
![Page 6: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/6.jpg)
6
Time 1
Input
a ab b ba
$
Stack
0
$$, q1 q2
a, $0$
a, 000a,1
b, $1$
b,111b, 0
![Page 7: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/7.jpg)
7
Time 3
Input
a bb b a
$
Stack
a
$
$$, q1 q2
a, $0$
a, 000a,1
b, $1$
b,111b, 0
0
![Page 8: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/8.jpg)
8
Time 4
Input
a bb b a
$
Stack
a
1
$$, q1 q2
a, $0$
a, 000a,1
b, $1$
b,111b, 0
![Page 9: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/9.jpg)
9
Time 5
Input
a bb b a
$
Stack
a
1
1
$$, q1 q2
a, $0$
a, 000a,1
b, $1$
b,111b, 0
![Page 10: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/10.jpg)
10
Time 6
Input
a bb b a
$
Stack
a
1
$$, q1 q2
a, $0$
a, 000a,1
b, $1$
b,111b, 0
1
![Page 11: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/11.jpg)
11
Time 7
Input
a bb b a
$
Stack
a
1
$$, q1 q2
a, $0$
a, 000a,1
b, $1$
b,111b, 0
![Page 12: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/12.jpg)
12
Time 8
Input
a bb b a a
$
Stack
$$, q1 q2
a, $0$
a, 000a,1
b, $1$
b,111b, 0
accept
![Page 13: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/13.jpg)
13
Formalities for NPDAs
![Page 14: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/14.jpg)
14
q1 q2a, bw
)},{(),,( 21 wqbaq
Transition function:
![Page 15: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/15.jpg)
15
q1
q2wba ,
q3wba ,
)},(),,{(),,( 321 wqwqbaq
Transition function:
![Page 16: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/16.jpg)
16
Formal Definition
Non-Deterministic Pushdown Automaton
NPDA
),,,δ,Γ,Σ,( 0 FzqQM
States
Input
alphabetStack
alphabet
Transition
function
Final
states
Stack
start
symbolInitial
state
![Page 17: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/17.jpg)
17
Instantaneous Description
),,( suq
Current
state Remaining
input
Current
stack
contents
![Page 18: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/18.jpg)
18
a,a
b, aq0 q1 q2 q3
Input
Stack
a a a b b b
$
a
a
b, a
Time 4:
, , $$
Example: Instantaneous Description
$),,( 1 aaabbbq
a
![Page 19: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/19.jpg)
19
a,a
b, aq0 q1 q2 q3
Input
Stack
a a a b b b
$
a
a
b, a
Time 5:
, , $$
Example: Instantaneous Description
$),,( 2 aabbq
a
![Page 20: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/20.jpg)
20
We write:
$),,($),,( 21 aabbqaaabbbq
Time 4 Time 5
![Page 21: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/21.jpg)
21
a,a
b, aq0 q1 q2 q3
b, a
, , $$
,$),(,$),($),,($),,(
$),,($),,($),,(
,$),(,$),(
3222
111
10
qqabqaabbq
aaabbbqaaabbbqaaabbbq
aaabbbqaaabbbq
A computation:
![Page 22: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/22.jpg)
22
,$),(,$),($),,($),,(
$),,($),,($),,(
,$),(,$),(
3222
111
10
qqabqaabbq
aaabbbqaaabbbqaaabbbq
aaabbbqaaabbbq
For convenience we write:
,$),(,$),( 30 qaaabbbq
![Page 23: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/23.jpg)
23
Formal Definition
Language of NPDA :M
)}',,(),,(:{)( 0 sqswqwML f
Initial state Final state
![Page 24: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/24.jpg)
24
Example:,$),(,$),( 30 qaaabbbq
a,a
b, aq0 q1 q2 q3
b, a
, , $$
NPDA :M
)(MLaaabbb
![Page 25: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/25.jpg)
25
,$),(,$),( 30 qbaq nn
a,a
b, aq0 q1 q2 q3
b, a
, , $$
NPDA :M
)(MLba nn
![Page 26: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/26.jpg)
26
a,a
b, aq0 q1 q2 q3
b, a
, , $$
NPDA :M
}0:{)( nbaML nnTherefore:
![Page 27: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/27.jpg)
27
NPDAs Accept Context-Free Languages
![Page 28: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/28.jpg)
28
Context-Free
Languages
(Grammars)
Languages
Accepted by
NPDAs
Theorem:
![Page 29: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/29.jpg)
29
Context-Free
Languages
(Grammars)
Languages
Accepted by
NPDAs
Proof - Step 1:
Convert any context-free grammar
to a NPDA with:
GM )()( MLGL
![Page 30: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/30.jpg)
30
Context-Free
Languages
(Grammars)
Languages
Accepted by
NPDAs
Proof - Step 2:
Convert any NPDA to a context-free
grammar with: G
M)()( MLGL
![Page 31: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/31.jpg)
31
ConvertingContext-Free Grammars
to NPDAs
![Page 32: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/32.jpg)
32
An example grammar:
T
TaT
bS
aSTbS
What is the equivalent NPDA?
![Page 33: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/33.jpg)
33q0 q1 2q
S, , $$
Grammar:
NPDA:
T
TaT
bS
aSTbS
,
,
,
,
T
TaT
bS
aSTbS
bb
aa
,
,
![Page 34: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/34.jpg)
34
The NPDA simulates
leftmost derivations of the grammar
L(Grammar) = L(NPDA)
![Page 35: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/35.jpg)
35
Grammar:
T
TaT
bS
aSTbS
A leftmost derivation:
abababTababTbaSTbS
![Page 36: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/36.jpg)
36
NPDA execution:
0q q1 2qS, , $$
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 0
b
current
state
![Page 37: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/37.jpg)
37q0 q1 2q
S, , $$
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 1
b
S
![Page 38: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/38.jpg)
38q0 2q
S, , $$
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 2
b
a
b
ST
q1
![Page 39: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/39.jpg)
39q0 2q
S, , $$
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 3
b
a
b
ST
q1
![Page 40: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/40.jpg)
40q0 2q
S, , $$
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 4
b
bTb
q1
![Page 41: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/41.jpg)
41q0 2q
S, , $$
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 5
b
bTb
q1
![Page 42: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/42.jpg)
42q0 2q
S, , $$
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 6
b
b
Ta
q1
![Page 43: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/43.jpg)
43q0 2q
S, , $$
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 7
b
b
Ta
q1
![Page 44: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/44.jpg)
44q0 2q
S, , $$
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 8
b
b
a
q1
![Page 45: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/45.jpg)
45q0 2q
S, , $$
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 9
b
b
q1
![Page 46: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/46.jpg)
46q0 q1 2q
S, , $$
T
TaT
bS
aSTbS
,
,
,
,
bb
aa
,
,
Input
Stack
$
a ab
Time 10
b
accept
![Page 47: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/47.jpg)
47
In general:
Given any grammar G
We can construct a NPDA M
With )()( MLGL
![Page 48: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/48.jpg)
48
Constructing NPDA from grammar :
q0 q1 2qS, , $$
wA, aa,
M
For any production
wA
For any terminal
a
G
![Page 49: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/49.jpg)
49
Grammar generates string G w
if and only if
NPDA acceptsM w
)()( MLGL
![Page 50: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/50.jpg)
50
Therefore:
For any context-free language
there is an NPDA
that accepts the same language
![Page 51: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/51.jpg)
51
ConvertingNPDAs
toContext-Free Grammars
![Page 52: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/52.jpg)
52
For any NPDA M
we will construct
a context-free grammar withG
)()( GLML
![Page 53: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/53.jpg)
53
Intuition:
G
The grammar simulates the machine
A derivation in Grammar :
abcABCabcS
Current configuration in NPDA M
![Page 54: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/54.jpg)
54
in NPDA M
abcABCabcS
Input processed Stack contents
terminals variables
GA derivation in Grammar :
![Page 55: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/55.jpg)
55
Some Necessary Modifications
First, we modify the NPDA:
• It has a single final state
• It empties the stack
when it accepts the input
Original NPDA Empty Stack
fq
fq
![Page 56: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/56.jpg)
56
Second, we modify the NPDA transitions:
all transitions will have form
iq jqBa,
or
iq jqCDBa ,
symbolsstack :,, DCB
![Page 57: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/57.jpg)
57
$,0q fq
a, $0$
a, 000a,1
b, $1$
b,111b, 0
}:{)( ba nnwML
Example of a NPDA in correct form:
symbolstack initial :$
![Page 58: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/58.jpg)
58
The Grammar Construction
)( jiBqq
In grammar :G
Terminals:
Input symbols of NPDA
states
Stack symbol
Variables:
![Page 59: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/59.jpg)
59
iq jqBa,For each transition
We add production aBqq ji )(
![Page 60: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/60.jpg)
60
For each transition
We add production ))(()( klljki DqqCqqaBqq
iq jqCDBa ,
For all states lk qq ,
![Page 61: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/61.jpg)
61
Start Variable: )$( fo qq
Stack bottom symbol
Start state final state
![Page 62: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/62.jpg)
62
Example:
$,0q fq
a, $0$
a, 000a,1
b, $1$
b,111b, 0
aqq )1( 00Grammar production:
![Page 63: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/63.jpg)
63
Example:
$,0q fq
a, $0$
a, 000a,1
b, $1$
b,111b, 0
)$)(1(|)$)(1()$(
)$)(1(|)$)(1()$(
00000
00000000
fffff
ff
qqqqbqqqqbqq
qqqqbqqqqbqq
Grammar productions:
![Page 64: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/64.jpg)
64
Example:
$,0q fq
a, $0$
a, 000a,1
b, $1$
b,111b, 0
Grammar production: )$( 0 fqq
![Page 65: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/65.jpg)
65
)$)(1(|)$)(1()$(
)$)(1(|)$)(1()$(
00000
00000000
fffff
ff
qqqqbqqqqbqq
qqqqbqqqqbqq
)1)(1(|)1)(1()1(
)1)(1(|)1)(1()1(
00000
00000000
fffff
ff
qqqqbqqqqbqq
qqqqbqqqqbqq
)$)(0(|)$)(0()$(
)$)(0(|)$)(0()$(
00000
00000000
fffff
ff
qqqqaqqqqaqq
qqqqaqqqqaqq
Resulting Grammar: ablestart vari:)$( 0 fqq
![Page 66: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/66.jpg)
66
)0)(0(|)0)(0()0(
)0)(0(|)0)(0()0(
00000
00000000
fffff
ff
qqqqaqqqqaqq
qqqqaqqqqaqq
bqq
aqq
)0(
)1(
00
00
)$( 0 fqq
![Page 67: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/67.jpg)
67
Derivation of string abba
)$( 0 fqq )$)(0( 000 fqqqqa
)$( 0 fqqab
)$)(1( 000 fqqqqabb
)$( 0 fqqabba abba
![Page 68: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/68.jpg)
68
In general, in Grammar:
wqq f
)$( 0
if and only if
w is accepted by the NPDA
![Page 69: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet](https://reader031.fdocuments.in/reader031/viewer/2022022511/5addbbb37f8b9a9d4d8d8fdb/html5/thumbnails/69.jpg)
69
Explanation:
By construction of Grammar:
wAqq ji
)(
if and only if
in the NPDA going from to
the stack doesn’t change below
and is removed from stack
iq jq
AA