SlideShare a Scribd company logo
© 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
© 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
© 2020 Wael Badawy
© 2020 Wael Badawy
4
1q 2q
3q
a
a
a
0q
}{aAlphabet =
Nondeterministic Finite Automaton (NFA)
© 2020 Wael Badawy
5
No transition
1q 2q
3q
a
a
a
0q
Two choices
No transition
}{aAlphabet =
© 2020 Wael Badawy
6
a a
0q
1q 2q
3q
a
a
First Choice
a
© 2020 Wael Badawy
7
a a
0q
1q 2q
3q
a
a
a
First Choice
© 2020 Wael Badawy
8
a a
0q
1q 2q
3q
a
a
a “accept”
First Choice
All input is consumed
© 2020 Wael Badawy
9
a a
0q
1q 2q
3q
a
a
Second Choice
a
© 2020 Wael Badawy
10
a a
0q
1q 2q
a
a
a
3q
Second Choice
“reject”
Input cannot be consumed
Automaton Halts
© 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
© 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
© 2020 Wael Badawy
13
a
0q
1q 2q
3q
a
a
Rejection example
a
© 2020 Wael Badawy
14
a
0q
1q 2q
3q
a
a
a
First Choice
“reject”
© 2020 Wael Badawy
15
Second Choice
a
0q
1q 2q
3q
a
a
a
© 2020 Wael Badawy
16
Second Choice
a
0q
1q 2q
a
a
a
3q “reject”
© 2020 Wael Badawy
17
Another Rejection example
a a
0q
1q 2q
3q
a
a
a
a
© 2020 Wael Badawy
18
a a
0q
1q 2q
3q
a
a
a
First Choice
a
© 2020 Wael Badawy
19
a a
0q
1q 2q
3q
a
a
a “reject”
First Choice
a
Input cannot be consumed
Automaton halts
© 2020 Wael Badawy
20
a a
0q
1q 2q
3q
a
a
Second Choice
a
a
© 2020 Wael Badawy
21
a a
0q
1q 2q
a
a
a
3q
Second Choice
“reject”
a
Input cannot be consumed
Automaton halts
© 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:
© 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
© 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
© 2020 Wael Badawy
25
1q 2q
3q
a
a
a
0q
Language accepted: }{aaL 
© 2020 Wael Badawy
Epsilon Transitions
26
1q 3qa
0q  2q a
© 2020 Wael Badawy
27
a a
1q 3qa
0q 2q a
© 2020 Wael Badawy
28
a a
1q 3qa
0q 2q a
© 2020 Wael Badawy
29
a a
1q 3qa
0q 2q a
input tape head does not move
Automaton changes state

© 2020 Wael Badawy
30
a a
1q 3qa
0q 2q a
“accept”
String is acceptedaa
all input is consumed

© 2020 Wael Badawy
31
a a
1q 3qa
0q 2q a
Rejection Example
a

© 2020 Wael Badawy
32
a a
1q 3qa
0q 2q a
a

© 2020 Wael Badawy
33
a a
1q 3qa
0q 2q a
(read head doesn’t move)
a

© 2020 Wael Badawy
34
a a
1q 3qa
0q 2q a
“reject”
String is rejectedaaa
a
Input cannot be consumed
Automaton halts

© 2020 Wael Badawy
35
Language accepted: }{aaL 
1q 3qa
0q 2q a
© 2020 Wael Badawy
36
Another NFA Example
0q 1q 2qa b 3q

© 2020 Wael Badawy
37
a b
0q 1q 2qa b 3q

© 2020 Wael Badawy
38
0q 2qa b 3q
a b
1q 

© 2020 Wael Badawy
39
a b
0q 1qa b 3q2q
“accept”


© 2020 Wael Badawy
40
0q a b
a b
Another String
a b
1q 2q 3q

© 2020 Wael Badawy
41
0q a b
a b a b
1q 2q 3q

© 2020 Wael Badawy
42
0q a b
a b a b
1q 2q 3q

© 2020 Wael Badawy
43
0q a b
a b a b
1q 2q 3q

© 2020 Wael Badawy
44
0q a b
a b a b
1q 2q 3q

© 2020 Wael Badawy
45
0q a b
a b a b
1q 2q 3q

© 2020 Wael Badawy
46
a b a b
0q a b
1q 2q 3q
“accept”


© 2020 Wael Badawy
47
 
  *
...,,,
abab
ababababababL


Language accepted
0q 1q 2qa b 3q

© 2020 Wael Badawy
Another NFA Example
48
0q 1q 2q
0
1
1,0

© 2020 Wael Badawy
49
 
 *
10
...,101010,1010,10,

 L
0q 1q 2q
0
1
1,0
Language accepted
(redundant
state)

© 2020 Wael Badawy
50
Simple Automata
0q
2M
0q
1M
{})( 1 ML }{)( 2 ML
© 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 
© 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

© 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
© 2020 Wael Badawy
54
   10 1, qq 
0
1
1,0
0q 1q 2q
States reachable from scanning0q 1

© 2020 Wael Badawy
55
0q
0
1
1,0
},{)0,( 201 qqq 
1q 2q
States reachable from scanning1q 0

© 2020 Wael Badawy
56
0q
0
1
1,0
1q 2q
}{),( 20 qq 
States reachable from with one transition
scanning no input symbol
0q

© 2020 Wael Badawy
57
0q
0
1
1,0
1q 2q
)1,( 2q
States reachable from scanning2q 1

© 2020 Wael Badawy
Extended Transition Function
58
*

0q
5q4q
3q2q1qa
aa
b
   10
*
, qaq 
Similar with but applied on strings


© 2020 Wael Badawy
59
   540
*
,, qqaaq 
5q4q
3q2q1qa
aa
b
States reachable from scanning0q aa
0q 

© 2020 Wael Badawy
60
   0320
*
,,, qqqabq 
0q
5q4q
3q2q1qa
aa
b
States reachable from scanning0q ab


© 2020 Wael Badawy
61
Special case:
  ,*
qq
for any state q
© 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
© 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
© 2020 Wael Badawy
64
0q kq
mw
),( 0
*
mwq
 MLwm 
Fqk 
iq
jq
mw
mw
© 2020 Wael Badawy
65
0q
5q4q
3q2q1qa
aa
b 
   540
*
,, qqaaq  )(MLaa
 50,qqF 
F

© 2020 Wael Badawy
66
0q
5q4q
3q2q1qa
aa
b
   0320
*
,,, qqqabq   MLab
 50,qqF 
F


© 2020 Wael Badawy
67
0q
5q4q
3q2q1qa
aa
b
 50,qqF 
   540
*
,, qqabaaq  )(MLabaa 
F


© 2020 Wael Badawy
68
0q
5q4q
3q2q1qa
aa
b
 50,qqF 
   10
*
, qabaq   MLaba
F


© 2020 Wael Badawy
69
0q
5q4q
3q2q1qa
aa
b
      }{
**
aaababML 


70
NFAs accept the Regular
Languages
70
© 2020 Wael Badawy
Equivalence of Machines
Definition:
Machine is equivalent to machine
if
71
1M 2M
   21 MLML 
© 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
© 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
© 2020 Wael Badawy
74
Languages
accepted
by NFAs
Regular
Languages

Languages
accepted
by NFAs
Regular
Languages

we need to showProof:
AND
© 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
© 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
© 2020 Wael Badawy
Conversion of NFA to DFA
77
a
b
a

0q 1q 2q
NFA
DFA
 0q
M
M
© 2020 Wael Badawy
78
a
b
a
0q 1q 2q
NFA
DFA
 0q  21,qq
a
M
M
},{),( 210
*
qqaq 

© 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

© 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
© 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
© 2020 Wael Badawy
82
a
b
a
0q 1q 2q
NFA
DFA
 0q  21,qq
a

b
ab
ba,
M
M
trap state

© 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,

© 2020 Wael Badawy
General Conversion Procedure
Input: an NFA
Output: an equivalent DFA
with
84
M
M
  )(MLML 
© 2020 Wael Badawy
The NFA has states
The DFA has states from the power set
85
,...,, 210 qqq
        ....,,,,,,,, 3211010 qqqqqqq
© 2020 Wael Badawy
1. Initial state of NFA:
Initial state of DFA:
86
0q
   ,, 00
*
qq 
Conversion Procedure Steps
step
 ,0q
© 2020 Wael Badawy
87
a
b
a
0q 1q 2q
NFA
DFA
 0q
M
M
Example
   00
*
, qq 

© 2020 Wael Badawy
2. For every DFA’s state
compute in the NFA
add transition to DFA
88
},...,,{ mji qqq
 
 
 aq
aq
aq
m
j
i
,*
...
,*
,*





},...,,{ nlk qqq 
  },...,,{},,...,,{ nlkmji qqqaqqq 

Union
step
© 2020 Wael Badawy
89
a
b
a
0q 1q 2q
NFA
 0q  21,qq
a
DFA
},{),(* 210 qqaq 
    210 ,, qqaq 
M
M
Example

© 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
© 2020 Wael Badawy
91
a
b
a
0q 1q 2q
NFA
DFA
 0q  21,qq
a

b
ab
ba,
M
M
Example

© 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
© 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

© 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:
© 2020 Wael Badawy
95
   MLML First we show:
)(MLw
We only need to prove:
)(MLw 
© 2020 Wael Badawy
96
)(MLw
w
kaaaw 21
0q fq
0q fq1a 2a ka
symbols
Consider
NFA
© 2020 Wael Badawy
97
ia
ia
denotes a possible sub-path like
iq jq
iq jq
symbol
symbol
…… ……    
© 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
© 2020 Wael Badawy
99
0q mq
rnaaav n  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
© 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
© 2020 Wael Badawy
101
Induction hypothesis: kv  ||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
© 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
eq1ka
1ka
},{ eq
NFA
DFA
Then this is true by construction of M
},{ 0 q
© 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
© 2020 Wael Badawy
104
We have shown:    MLML 
With a similar proof
we can show:    MLML 
END OF PROOF
   MLML Therefore:

More Related Content

PDF
Turing variations
Wael Badawy
 
PPT
Ipmi spec ch33_simon_20110516
davidsmc
 
PDF
Turing Machine
Wael Badawy
 
PDF
Regular properties
Wael Badawy
 
PDF
Time complexity
Wael Badawy
 
PDF
Universal turing
Wael Badawy
 
Turing variations
Wael Badawy
 
Ipmi spec ch33_simon_20110516
davidsmc
 
Turing Machine
Wael Badawy
 
Regular properties
Wael Badawy
 
Time complexity
Wael Badawy
 
Universal turing
Wael Badawy
 

Similar to N F A - Non Deterministic Finite Automata (9)

PDF
Regular pumping
Wael Badawy
 
PDF
Pda accept context free
Wael Badawy
 
PPTX
Np complete reductions
Wael Badawy
 
PDF
Regular expressions
Wael Badawy
 
PDF
Regular pumping examples
Wael Badawy
 
PPTX
RBT tool operating in eclipse software.pptx
TCShekar1
 
PPTX
10 Inter-VLتاتتاتتتAN Communication.pptx
ssuserb8f225
 
PPTX
10 Inter-VLتاتتاتتتAN Communication.pptx
ssuserb8f225
 
PDF
CADLAD: Device-aware Bitrate Ladder Construction for HTTP Adaptive Streaming
Minh Nguyen
 
Regular pumping
Wael Badawy
 
Pda accept context free
Wael Badawy
 
Np complete reductions
Wael Badawy
 
Regular expressions
Wael Badawy
 
Regular pumping examples
Wael Badawy
 
RBT tool operating in eclipse software.pptx
TCShekar1
 
10 Inter-VLتاتتاتتتAN Communication.pptx
ssuserb8f225
 
10 Inter-VLتاتتاتتتAN Communication.pptx
ssuserb8f225
 
CADLAD: Device-aware Bitrate Ladder Construction for HTTP Adaptive Streaming
Minh Nguyen
 
Ad

More from Wael Badawy (20)

PDF
HTML introduction
Wael Badawy
 
PPTX
Parsers -
Wael Badawy
 
PPTX
Computer Vision Cameras
Wael Badawy
 
PPTX
Computer Vision Gans
Wael Badawy
 
PPTX
Computer Vision image classification
Wael Badawy
 
PPTX
Computer Vision Structure from motion
Wael Badawy
 
PDF
Pushdown Automota
Wael Badawy
 
PPTX
Computer Vision sfm
Wael Badawy
 
PPTX
Computer vision - photometric
Wael Badawy
 
PPTX
Computer vision - light
Wael Badawy
 
PPTX
Computer vision - two view geometry
Wael Badawy
 
PPTX
Computer Vision - Stereo Vision
Wael Badawy
 
PPTX
Computer Vision - Single View
Wael Badawy
 
PPTX
Computer Vision single view Modelling
Wael Badawy
 
PPTX
Computer Vision panoramas
Wael Badawy
 
PPTX
Computer Vision panoramas
Wael Badawy
 
PPTX
Computer Vision - cameras
Wael Badawy
 
PPTX
Computer Vision - RANSAC
Wael Badawy
 
PPTX
Computer Vision RANSAC
Wael Badawy
 
PPTX
Computer Vision alignment
Wael Badawy
 
HTML introduction
Wael Badawy
 
Parsers -
Wael Badawy
 
Computer Vision Cameras
Wael Badawy
 
Computer Vision Gans
Wael Badawy
 
Computer Vision image classification
Wael Badawy
 
Computer Vision Structure from motion
Wael Badawy
 
Pushdown Automota
Wael Badawy
 
Computer Vision sfm
Wael Badawy
 
Computer vision - photometric
Wael Badawy
 
Computer vision - light
Wael Badawy
 
Computer vision - two view geometry
Wael Badawy
 
Computer Vision - Stereo Vision
Wael Badawy
 
Computer Vision - Single View
Wael Badawy
 
Computer Vision single view Modelling
Wael Badawy
 
Computer Vision panoramas
Wael Badawy
 
Computer Vision panoramas
Wael Badawy
 
Computer Vision - cameras
Wael Badawy
 
Computer Vision - RANSAC
Wael Badawy
 
Computer Vision RANSAC
Wael Badawy
 
Computer Vision alignment
Wael Badawy
 
Ad

Recently uploaded (20)

PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PPTX
How to Apply for a Job From Odoo 18 Website
Celine George
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
How to Apply for a Job From Odoo 18 Website
Celine George
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 

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
  • 3. © 2020 Wael Badawy
  • 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 
  • 26. © 2020 Wael Badawy Epsilon Transitions 26 1q 3qa 0q  2q a
  • 27. © 2020 Wael Badawy 27 a a 1q 3qa 0q 2q a
  • 28. © 2020 Wael Badawy 28 a a 1q 3qa 0q 2q a
  • 29. © 2020 Wael Badawy 29 a a 1q 3qa 0q 2q a input tape head does not move Automaton changes state 
  • 30. © 2020 Wael Badawy 30 a a 1q 3qa 0q 2q a “accept” String is acceptedaa all input is consumed 
  • 31. © 2020 Wael Badawy 31 a a 1q 3qa 0q 2q a Rejection Example a 
  • 32. © 2020 Wael Badawy 32 a a 1q 3qa 0q 2q a a 
  • 33. © 2020 Wael Badawy 33 a a 1q 3qa 0q 2q a (read head doesn’t move) a 
  • 34. © 2020 Wael Badawy 34 a a 1q 3qa 0q 2q a “reject” String is rejectedaaa a Input cannot be consumed Automaton halts 
  • 35. © 2020 Wael Badawy 35 Language accepted: }{aaL  1q 3qa 0q 2q a
  • 36. © 2020 Wael Badawy 36 Another NFA Example 0q 1q 2qa b 3q 
  • 37. © 2020 Wael Badawy 37 a b 0q 1q 2qa b 3q 
  • 38. © 2020 Wael Badawy 38 0q 2qa b 3q a b 1q  
  • 39. © 2020 Wael Badawy 39 a b 0q 1qa b 3q2q “accept”  
  • 40. © 2020 Wael Badawy 40 0q a b a b Another String a b 1q 2q 3q 
  • 41. © 2020 Wael Badawy 41 0q a b a b a b 1q 2q 3q 
  • 42. © 2020 Wael Badawy 42 0q a b a b a b 1q 2q 3q 
  • 43. © 2020 Wael Badawy 43 0q a b a b a b 1q 2q 3q 
  • 44. © 2020 Wael Badawy 44 0q a b a b a b 1q 2q 3q 
  • 45. © 2020 Wael Badawy 45 0q a b a b a b 1q 2q 3q 
  • 46. © 2020 Wael Badawy 46 a b a b 0q a b 1q 2q 3q “accept”  
  • 47. © 2020 Wael Badawy 47     * ...,,, abab ababababababL   Language accepted 0q 1q 2qa b 3q 
  • 48. © 2020 Wael Badawy Another NFA Example 48 0q 1q 2q 0 1 1,0 
  • 49. © 2020 Wael Badawy 49    * 10 ...,101010,1010,10,   L 0q 1q 2q 0 1 1,0 Language accepted (redundant state) 
  • 50. © 2020 Wael Badawy 50 Simple Automata 0q 2M 0q 1M {})( 1 ML }{)( 2 ML
  • 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
  • 54. © 2020 Wael Badawy 54    10 1, qq  0 1 1,0 0q 1q 2q States reachable from scanning0q 1 
  • 55. © 2020 Wael Badawy 55 0q 0 1 1,0 },{)0,( 201 qqq  1q 2q States reachable from scanning1q 0 
  • 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   
  • 70. 70 NFAs accept the Regular Languages 70
  • 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 DFA’s 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  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  ||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 eq1ka 1ka },{ 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:

Editor's Notes