This document contains a disclaimer and copyright information for a video presentation on non-deterministic finite automata (NFA). It notes that the video is optimized for large displays using a patented Egyptian video codec and is available as a podcast. It specifies the video is copyrighted and any reproduction or republication requires prior written consent. It also notes the video is intended for education only and no warranty or liability is provided.
1 of 104
Download to read offline
More Related Content
N F A - Non Deterministic Finite Automata
1. 息 2020 Wael Badawy
1
Non-Deterministic Finite Automata
1
DISCLAIMER:
This video is optimized for HD large display using
patented and patent-pending Nile Codec, the first
Egyptian Video Codec for more information,
PLEASE check https://NileCodec.com
Also available as a PodCast
2. 息 2020 Wael Badawy
Copyright 息 2020 Wael Badawy. All rights reserved
This video is subject to copyright owned by Wael Badawy WB. Any
reproduction or republication of all or part of this video is expressly prohibited
unless WB has explicitly granted its prior written consent. All other rights
reserved.
This video is intended for education and information only and is offered AS IS,
without any warranty of the accuracy or the quality of the content. Any other
use is strictly prohibited. The viewer is fully responsible to verify the accuracy
of the contents received without any claims of costs or liability arising .
The names, trademarks service marked as logos of WB or the sponsors
appearing in this video may not be used in any any product or service,
without prior express written permission from WB and the video sponsors
Neither WB nor any party involved in creating, producing or delivering
information and material via this video shall be liable for any direction,
incidental, consequential, indirect of punitive damages arising out of access
to, use or inability to use this content or any errors or omissions in the
content thereof.
If you will continue to watch this video, you agree to the terms above and
other terms that may be available on http://nu.edu.eg & https://caiwave.net
2
4. 息 2020 Wael Badawy
4
1q 2q
3q
a
a
a
0q
}{aAlphabet =
Nondeterministic Finite Automaton (NFA)
5. 息 2020 Wael Badawy
5
No transition
1q 2q
3q
a
a
a
0q
Two choices
No transition
}{aAlphabet =
6. 息 2020 Wael Badawy
6
a a
0q
1q 2q
3q
a
a
First Choice
a
7. 息 2020 Wael Badawy
7
a a
0q
1q 2q
3q
a
a
a
First Choice
8. 息 2020 Wael Badawy
8
a a
0q
1q 2q
3q
a
a
a accept
First Choice
All input is consumed
9. 息 2020 Wael Badawy
9
a a
0q
1q 2q
3q
a
a
Second Choice
a
10. 息 2020 Wael Badawy
10
a a
0q
1q 2q
a
a
a
3q
Second Choice
reject
Input cannot be consumed
Automaton Halts
11. 息 2020 Wael Badawy
11
A NFA accepts a string:
if there is a computation path of the NFA
that accepts the string
all the symbols of input string are processed
and
the last is an accepting state
12. 息 2020 Wael Badawy
12
aa is accepted by the NFA:
0q
1q 2q
3q
a
a
a
accept
0q
1q 2q
a
a
a
3q reject
because this
computation
accepts aa
this computation
is ignored
13. 息 2020 Wael Badawy
13
a
0q
1q 2q
3q
a
a
Rejection example
a
14. 息 2020 Wael Badawy
14
a
0q
1q 2q
3q
a
a
a
First Choice
reject
15. 息 2020 Wael Badawy
15
Second Choice
a
0q
1q 2q
3q
a
a
a
16. 息 2020 Wael Badawy
16
Second Choice
a
0q
1q 2q
a
a
a
3q reject
17. 息 2020 Wael Badawy
17
Another Rejection example
a a
0q
1q 2q
3q
a
a
a
a
18. 息 2020 Wael Badawy
18
a a
0q
1q 2q
3q
a
a
a
First Choice
a
19. 息 2020 Wael Badawy
19
a a
0q
1q 2q
3q
a
a
a reject
First Choice
a
Input cannot be consumed
Automaton halts
20. 息 2020 Wael Badawy
20
a a
0q
1q 2q
3q
a
a
Second Choice
a
a
21. 息 2020 Wael Badawy
21
a a
0q
1q 2q
a
a
a
3q
Second Choice
reject
a
Input cannot be consumed
Automaton halts
22. 息 2020 Wael Badawy
22
A NFA rejects a string:
if there is no computation of the NFA
that accepts the string.
All the input is consumed and the
automaton is in a non accepting state
The input cannot be consumed
OR
For each possible computation path:
23. 息 2020 Wael Badawy
23
a is rejected by the NFA:
0q
1q 2q
a
a
a
3q reject
0q
1q 2q
a
a
a
3q
reject
All possible computations lead to rejection
24. 息 2020 Wael Badawy
24
aaa is rejected by the NFA:
0q
1q 2q
3q
a
a
a
reject
0q
1q 2q
a
a
a
3q reject
All possible computations lead to rejection
25. 息 2020 Wael Badawy
25
1q 2q
3q
a
a
a
0q
Language accepted: }{aaL
51. 息 2020 Wael Badawy
51
0q
2q
1qa
a
a
0q 1qa
}{=)( 1 aML
2M1MNFA DFA
NFAs are interesting because we can
express languages easier than DFAs
}{)( 2 aML
52. 息 2020 Wael Badawy
Formal Definition of NFAs
52
FqQM ,,,, 0わ
:Q
:
:0q
:F
Set of states, i.e. 210 ,, qqq
: Input aplhabet, i.e. ba,
Transition function
Initial state
Accepting states
53. 息 2020 Wael Badawy
53
kqqqxq ,,,, 21 緒
Transition Function
q
1q
2q
kq
x
x
x
resulting states reached
by following one transition
with input symbol x
56. 息 2020 Wael Badawy
56
0q
0
1
1,0
1q 2q
}{),( 20 qq 緒ワ
States reachable from with one transition
scanning no input symbol
0q
57. 息 2020 Wael Badawy
57
0q
0
1
1,0
1q 2q
)1,( 2q
States reachable from scanning2q 1
58. 息 2020 Wael Badawy
Extended Transition Function
58
*
0q
5q4q
3q2q1qa
aa
b
10
*
, qaq 緒
Similar with but applied on strings
59. 息 2020 Wael Badawy
59
540
*
,, qqaaq 緒
5q4q
3q2q1qa
aa
b
States reachable from scanning0q aa
0q
60. 息 2020 Wael Badawy
60
0320
*
,,, qqqabq 緒
0q
5q4q
3q2q1qa
aa
b
States reachable from scanning0q ab
61. 息 2020 Wael Badawy
61
Special case:
ワ ,*
qq
for any state q
62. 息 2020 Wael Badawy
62
wqq ij ,*
わ : there is a walk from to
with label
iq jq
w
iq jq
w
kw 鰹鰹 21
1 2 k
iq jq
In general
63. 息 2020 Wael Badawy
The Language of an NFA
The language accepted by is:
Where for each
and there is some
63
M
M
nwwwML ,...,, 21
},,,...,{),( 0
*
jkim qqqwq 緒
Fqk (accepting state)
mw
64. 息 2020 Wael Badawy
64
0q kq
mw
),( 0
*
mwq
MLwm
Fqk
iq
jq
mw
mw
65. 息 2020 Wael Badawy
65
0q
5q4q
3q2q1qa
aa
b
540
*
,, qqaaq 緒 )(MLaa
50,qqF
F
66. 息 2020 Wael Badawy
66
0q
5q4q
3q2q1qa
aa
b
0320
*
,,, qqqabq 緒 MLab
50,qqF
F
67. 息 2020 Wael Badawy
67
0q
5q4q
3q2q1qa
aa
b
50,qqF
540
*
,, qqabaaq 緒 )(MLabaa
F
68. 息 2020 Wael Badawy
68
0q
5q4q
3q2q1qa
aa
b
50,qqF
10
*
, qabaq 緒 MLaba
F
69. 息 2020 Wael Badawy
69
0q
5q4q
3q2q1qa
aa
b
}{
**
aaababML
71. 息 2020 Wael Badawy
Equivalence of Machines
Definition:
Machine is equivalent to machine
if
71
1M 2M
21 MLML
72. 息 2020 Wael Badawy
72
0q 1q
0
1
0q 1q 2q
0
1
1
0
1,0
NFA
DFA
*}10{1 ML
*}10{2 ML
1M
2M
Example of equivalent machines
73. 息 2020 Wael Badawy
73
Theorem:
Languages
accepted
by NFAs
Regular
Languages
NFAs and DFAs have the same computation power,
namely, they accept the same set of languages
Languages
accepted
by DFAs
74. 息 2020 Wael Badawy
74
Languages
accepted
by NFAs
Regular
Languages
Languages
accepted
by NFAs
Regular
Languages
we need to showProof:
AND
75. 息 2020 Wael Badawy
75
Languages
accepted
by NFAs
Regular
Languages
Proof-Step 1
Every DFA is trivially a NFA
Any language accepted by a DFA
is also accepted by a NFA
L
76. 息 2020 Wael Badawy
76
Languages
accepted
by NFAs
Regular
Languages
Proof-Step 2
Any NFA can be converted to an
equivalent DFA
Any language accepted by a NFA
is also accepted by a DFA
L
77. 息 2020 Wael Badawy
Conversion of NFA to DFA
77
a
b
a
0q 1q 2q
NFA
DFA
0q
M
M
78. 息 2020 Wael Badawy
78
a
b
a
0q 1q 2q
NFA
DFA
0q 21,qq
a
M
M
},{),( 210
*
qqaq 緒
79. 息 2020 Wael Badawy
79
a
b
a
0q 1q 2q
NFA
DFA
0q 21,qq
a
b
M
M
),( 0
*
bq empty set
trap state
80. 息 2020 Wael Badawy
80
a
b
a
0q 1q 2q
NFA
DFA
0q 21,qq
a
b
a
M
M
},{),( 211
*
qqaq 緒
),( 2
*
aq
21,qq
union
81. 息 2020 Wael Badawy
81
a
b
a
0q 1q 2q
NFA
DFA
0q 21,qq
a
b
ab
M
M
}{),( 01
*
qbq 緒
}{),( 02
*
qbq 緒
0q
union
82. 息 2020 Wael Badawy
82
a
b
a
0q 1q 2q
NFA
DFA
0q 21,qq
a
b
ab
ba,
M
M
trap state
83. 息 2020 Wael Badawy
83
a
b
a
0q 1q 2q
NFA
DFA
0q 21,qq
a
b
a
b
ba,
M
M
END OF CONSTRUCTION
Fq 1
Fqq 21,
84. 息 2020 Wael Badawy
General Conversion Procedure
Input: an NFA
Output: an equivalent DFA
with
84
M
M
)(MLML
85. 息 2020 Wael Badawy
The NFA has states
The DFA has states from the power set
85
,...,, 210 qqq
....,,,,,,,, 3211010 qqqqqqq
86. 息 2020 Wael Badawy
1. Initial state of NFA:
Initial state of DFA:
86
0q
緒,, 00
*
qq 緒ワ
Conversion Procedure Steps
step
緒,0q
87. 息 2020 Wael Badawy
87
a
b
a
0q 1q 2q
NFA
DFA
0q
M
M
Example
00
*
, qq 緒ワ
88. 息 2020 Wael Badawy
2. For every DFAs state
compute in the NFA
add transition to DFA
88
},...,,{ mji qqq
aq
aq
aq
m
j
i
,*
...
,*
,*
},...,,{ nlk qqq
},...,,{},,...,,{ nlkmji qqqaqqq 緒
Union
step
89. 息 2020 Wael Badawy
89
a
b
a
0q 1q 2q
NFA
0q 21,qq
a
DFA
},{),(* 210 qqaq 緒
緒 210 ,, qqaq 緒
M
M
Example
90. 息 2020 Wael Badawy
3. Repeat Step 2 for every state in DFA and
symbols in alphabet until no more states can be
added in the DFA
90
step
91. 息 2020 Wael Badawy
91
a
b
a
0q 1q 2q
NFA
DFA
0q 21,qq
a
b
ab
ba,
M
M
Example
92. 息 2020 Wael Badawy
4. For any DFA state
if some is accepting state in NFA
Then,
is accepting state in DFA
92
},...,,{ mji qqq
jq
},...,,{ mji qqq
step
93. 息 2020 Wael Badawy
93
a
b
a
0q 1q 2q
NFA
DFA
0q 21,qq
a
b
a
b
ba,
Fq 1
Fqq 21,
M
M
Example
94. 息 2020 Wael Badawy
94
If we convert NFA to DFA
then the two automata are equivalent:
M
MLML
M
Lemma:
Proof:
MLML
MLML
AND
We need to show:
95. 息 2020 Wael Badawy
95
MLML First we show:
)(MLw
We only need to prove:
)(MLw
96. 息 2020 Wael Badawy
96
)(MLw
w
kaaaw 21
0q fq
0q fq1a 2a ka
symbols
Consider
NFA
97. 息 2020 Wael Badawy
97
ia
ia
denotes a possible sub-path like
iq jq
iq jq
symbol
symbol
98. 息 2020 Wael Badawy
98
0q fq
raaaw 21
1a 2a ra
:M
},{ 0 q
1a 2a ra
:M
},{ fq
)(MLw
)(MLw
We will show that if
then
NFA
DFA
state
label
state
label
99. 息 2020 Wael Badawy
99
0q mq
rnaaav n o 21
1a 2a na
:M
1a 2a na
:M
},{ iq
iq jq lq
},{ jq },{ lq },{ mq
More generally, we will show that if in :M
(arbitrary prefix)
then
NFA
DFA
},{ 0 q
100. 息 2020 Wael Badawy
100
0q 1a
:M
1a
:M
},{ iq
iq
Proof by induction on
Induction Basis: 1av
|| v
is true by construction of M
NFA
DFA
1|| v
},{ 0 q
101. 息 2020 Wael Badawy
101
Induction hypothesis: kv o ||1
0q dq1a 2a ka
:M iq jq cq
1a 2a ka
:M
},{ iq },{ jq },{ cq },{ dq
kaaav 21
NFA
DFA
Suppose that the following hold
},{ 0 q
102. 息 2020 Wael Badawy
102
Induction Step: 1|| kv
0q dq1a 2a ka
:M iq jq cq
1a 2a ka
:M
},{ iq },{ jq },{ cq },{ dq
1121
緒 kk
v
k avaaaav
器鰹 駕
v
v
eq1ka
1ka
},{ eq
NFA
DFA
Then this is true by construction of M
},{ 0 q
103. 息 2020 Wael Badawy
103
0q fq
raaaw 21
1a 2a ra
:M
:M
},{ fq
)(MLw
)(MLw
Therefore if
NFA
DFA
then
},{ 0 q
1a 2a ra
104. 息 2020 Wael Badawy
104
We have shown: MLML
With a similar proof
we can show: MLML
END OF PROOF
MLML Therefore: