Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Alphabet = {a}
q1 a q2
a
q0
a
q3
2
Nondeterministic Finite Accepter (NFA)
Alphabet = {a}
Two choices q1 a q2
a
q0
a
q3
3
Nondeterministic Finite Accepter (NFA)
Alphabet = {a}
Two choices a
q1 q2 No transition
a
q0
a
q3 No transition
4
First Choice
a a
q1 a q2
a
q0
a
q3
5
First Choice
a a
q1 a q2
a
q0
a
q3
6
First Choice
a a
q1 a q2
a
q0
a
q3
7
First Choice
a a
q1 a q2 “accept”
a
q0
a
q3
8
Second Choice
a a
q1 a q2
a
q0
a
q3
9
Second Choice
a a
q1 a q2
a
q0
a
q3
10
Second Choice
a a
q1 a q2
a
q0
a
No transition:
q3
the automaton hangs
11
Second Choice
a a
q1 a q2
a
q0
a
q3 “reject”
12
Observation
13
Example
q1 a q2
a
q0
a
q3
14
Epsilon Transitions
q0 a q1 q1 a q3
15
a a
q0 a q1 q2 a q3
16
a a
q0 a q1 q2 a q3
17
(read head doesn’t move)
a a
q0 a q1 q2 a q3
18
a a
q0 a q1 q2 a q3
19
a a
“accept”
q0 a q1 q2 a q3
String aa is accepted
20
Language accepted: L {aa}
q0 a q1 q2 a q3
21
Another NFA Example
q0 a q1 b q2 q3
22
a b
q0 a q1 b q2 q3
23
a b
q0 a q1 b q2 q3
24
a b
q0 a q1 b q2 q3
25
a b
“accept”
q0 a q1 b q2 q3
26
Another String
a b a b
q0 a q1 b q2 q3
27
a b a b
q0 a q1 b q2 q3
28
a b a b
q0 a q1 b q2 q3
29
a b a b
q0 a q1 b q2 q3
30
a b a b
q0 a q1 b q2 q3
31
a b a b
q0 a q1 b q2 q3
32
a b a b
q0 a q1 b q2 q3
33
a b a b
“accept”
q0 a q1 b q2 q3
34
Language accepted
q0 a q1 b q2 q3
35
Another NFA Example
0
q0 q1 0, 1 q2
1
36
Language accepted
q0 , 1 q1
0
q0 q1 0, 1 q
2
1
39
(q1,0) {q0 , q2}
0
q0 q1 0, 1 q
2
1
40
(q0 ,) {q0 , q2 }
0
q0 q1 0, 1 q
2
1
41
(q2 ,1)
0
q0 q1 0, 1 q
2
1
42
Extended Transition Function
q0 , a q1
q4 q5
a a
q0 a q1 b q2 q3
43
q0 , aa q 4 , q 5
q4 q5
a a
q0 a q1 b q2 q3
44
q0 , ab q 2 , q3 , q0
q4 q5
a a
q0 a q1 b q2 q3
45
Formally
It holds q j qi , w
if and only if
46
The Language of an NFA M
F q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
q0 , aa q4 , q5 aa L( M )
47
F q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
ab LM
q0 , ab q2 , q3 , q0
48
F q0 ,q5
q4 q5
a a
a b
q0 q1 q2 q3
q0 , abaa q4 , q5 aaba L( M )
49
F q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
q0 , aba q1
aba LM
50
q4 q5
a a
q0 a q1 b q2
q3
LM aa ab* ab aa
51
Formally
The language accepted by NFA is: M
(final state)
52
w LM
(q0 , w)
qi
w
qk qk F
q0 w
w qj
53
Equivalence of NFAs and DFAs
Equivalence of Machines
if L M1 L M 2
55
Example
NFA M1
LM1 {10} * 0
q0 q1 0, 1 q2
1
DFA M2 0,1
LM 2 {10} * 0
q0 q1 1 q2
1
0
56
LM1 LM 2 10*
Since machines M1 and M 2 are equivalent
0
0, 1
NFA M1 q0
1
q1 q2
0,1
0
DFA M2 q0 q1 1 q2
1
0
57
Equivalence of NFAs and DFAs
Same power?
Accept the same languages?
58
Equivalence of NFAs and DFAs
Same power?
Accept the same languages?
59
We will prove:
Languages Languages
accepted accepted
by NFAs by DFAs
60
We will prove:
Languages Languages
accepted accepted
by NFAs by DFAs
61
Step 1
Languages Languages
accepted
by NFAs
accepted
by DFAs
62
Step 1
Languages Languages
accepted
by NFAs
accepted
by DFAs
63
Step 1
Languages Languages
accepted
by NFAs
accepted
by DFAs
Languages Languages
accepted
by NFAs
accepted
by DFAs
65
Step 2
Languages Languages
accepted
by NFAs
accepted
by DFAs
66
Step 2
Languages Languages
accepted
by NFAs
accepted
by DFAs
DFA
a, b
q0
68
NFA to DFA
NFA
a
q0 a q1 q2
b
DFA
q0 a
q1,q2
b
69
NFA to DFA
NFA
a
q0 a q1 q2
b
a
DFA
q0 a
q1,q2
b
70
NFA to DFA
NFA
a
q0 a q1 q2
b
a
DFA
q0 a
q1,q2
b
71
NFA to DFA
NFA
a
q0 a q1 q2
b
b a
DFA
q0 a
q1,q2
b
72
NFA to DFA
NFA
a
q0 a q1 q2
b
b a
DFA
q0 a
q1,q2
b
a, b
73
NFA to DFA
NFA
a
q0 a q1 q2
b
a
DFA b
q0 a
q1,q2
b
a, b
74
NFA to DFA: Remarks
75
If the NFA has states q0 , q1, q2 ,...
76
Procedure NFA to DFA
DFA
q0
78
Procedure NFA to DFA
2. For every DFA’s state {qi , q j ,..., qm }
Compute in the NFA
q i , a ,
{qi , qj ,..., qm
}
q j , a ,
Add transition
...
DFA
q0 a
q1,q2
q0 , a q1, q2
80
Procedure NFA to DFA
81
Example
NFA
a
q0 a q1 q2
b
b a
DFA
q0 a
q1,q2
b
a, b
82
Procedure NFA to DFA
83
Example
NFA
a
q0 a q1 q q1 F
2
b
a
DFA b
q0 a
q1,q2 q1, q2 F
b
a, b
84
Theorem
Take NFA M
L M L M
85
Finally
We have proven
Languages Languages
accepted accepted
by NFAs by DFAs
86
We have proven
Languages Languages
accepted accepted
by NFAs by DFAs
Regular Languages
87
We have proven
Languages Languages
accepted accepted
by NFAs by DFAs
88