Class3 - Nondeterministic Finite Accepters
Class3 - Nondeterministic Finite Accepters
Alphabet = {a}
q1
q0
q2
q3
1
Alphabet = {a}
Two choices
a
q0
Alphabet = {a}
q1
Two choices
a
q2
q0
q1
q2
No transition
q3
q3
No transition
First Choice
First Choice
a a
a a
q0
q1
q2
q0
q3
q1
q2
q3
5
1
PDF created with pdfFactory Pro trial version www.pdffactory.com
First Choice
First Choice
a a
a a
All input is consumed
a
q0
q1
q2
q0
q1
q2
accept
q3
q3
7
Second Choice
Second Choice
a a
a a
q0
q1
q2
q0
q1
q2
q3
q3
9
10
Second Choice
Second Choice
a a
a a
Input cannot be consumed
a
q0
q1
q3
q2
q0
No transition:
the automaton hangs
q1
q2
q3
11
reject
12
2
PDF created with pdfFactory Pro trial version www.pdffactory.com
Example
aa
q0
q2
q0
q1 a
q3
q3
q2
reject
14
Rejection example
First Choice
q0
q1
q2
q0
q1
q2
q3
q3
15
16
First Choice
Second Choice
a
reject
a
q0
q1
q2
q0
q3
q1
q2
q3
17
18
3
PDF created with pdfFactory Pro trial version www.pdffactory.com
Second Choice
Second Choice
q0
q1
q2
q1
q0
q2
q3
q3
reject
19
20
Example
An NFA rejects a string:
when there is no computation of the NFA
that accepts the string
q0
q1 a
21
q0
reject
q1 a
q2
q3
22
Rejection example
First Choice
a a a
a a a
q0
q3
q2
q1
q2
q0
q3
q1
q2
q3
23
24
4
PDF created with pdfFactory Pro trial version www.pdffactory.com
First Choice
First Choice
a a a
a a a
Input cannot be consumed
a
q0
q1
q2
No transition:
the automaton hangs
q3
q0
q1
q2
q3
25
26
Second Choice
Second Choice
a a a
a a a
q0
reject
q1
q2
q0
q1
q2
q3
q3
27
28
Second Choice
Second Choice
a a a
a a a
Input cannot be consumed
a
q0
q1
q3
q2
q0
No transition:
the automaton hangs
q1
q2
q3
29
reject
30
5
PDF created with pdfFactory Pro trial version www.pdffactory.com
aaa
Language accepted:
reject
a
q0
q1
q2
q0
q1 a
q3
q3
q2
q0
reject
q1
L = {aa}
q2
q3
31
32
Lambda Transitions
a a
q0
q1
q2
q3
q0
q1
q2
q3
33
34
a a
q0
q1
q2
q3
q0
35
q1
q2
q3
36
6
PDF created with pdfFactory Pro trial version www.pdffactory.com
a a
accept
q0
q1
q2
q3
q0
String
q1
q2
q3
aa is accepted
37
38
Rejection Example
a a a
q0
a a a
q1
q2
q3
q0
q1
q2
q3
39
40
q0
a a a
q1
q2
q3
q0
q1
q2
q3
No transition:
the automaton hangs
41
42
7
PDF created with pdfFactory Pro trial version www.pdffactory.com
L = {aa}
reject
q0
String
q1
q2
q3
q0
q1
q2
q3
aaa is rejected
43
44
a b
q0
q1
q2
q3
q0
q1
q2
q3
45
a b
q0
46
a b
q1
q2
q3
q0
q1
q2
q3
47
48
8
PDF created with pdfFactory Pro trial version www.pdffactory.com
Another String
a b
a b a b
accept
q0
q1
q2
q3
q0
q1
q2
q3
49
a b a b
q0
50
a b a b
q1
q2
q3
q0
q1
q2
q3
51
a b a b
q0
52
a b a b
q1
q2
q3
q0
q1
q2
q3
53
54
9
PDF created with pdfFactory Pro trial version www.pdffactory.com
a b a b
q0
a b a b
q1
q2
q3
q0
q1
q2
q3
55
56
Language accepted
a b a b
= {ab}+
accept
q0
q1
q2
q3
q0
q1
q2
q3
57
58
Language accepted
q0
q1
0, 1 q
2
q0
q1
0, 1 q
2
59
60
10
PDF created with pdfFactory Pro trial version www.pdffactory.com
Remarks:
NFA
M1
q0
M2
L( M1 ) = {}
L( M 2 ) = {}
q0
DFA
M1
q2
q1
q0
q0
61
L ( M1 ) = {a}
M = (Q, , , q0 , F )
Set of states, i.e.
{a, b}
Initial state
F:
Final states
L ( M 2 ) = {a}
q0
q1
0, 1 q
2
64
62
63
q0
q1
(q0 , 1) = {q1}
: Transition function
q0 :
a
a
Transition Function
Q:
M2
q1
0, 1 q
2
q0
q1
0, 1 q
2
65
66
11
PDF created with pdfFactory Pro trial version www.pdffactory.com
* (q0 , a ) = {q1}
(q2 ,1) =
0
q0
q1
q5
q4
0, 1 q
2
a
a
q0
q0
a
b
q2
q3
q0
68
a
b
q1
q3
70
F = {q0 ,q5 }
q j * (qi , w)
q5
q4
a
q0
if and only if
there is a walk from
with label w
q2
69
Formally
It holds
q3
q5
q4
q1
* (q0 , ab ) = {q2 , q3 , q0 }
q5
a
q2
* (q0 , aa ) = {q4 , q5 }
q1
67
q4
a
b
q1
q2
q3
qi
to
qj
* (q0 , aa ) = {q4 , q5 }
71
aa L(M )
72
12
PDF created with pdfFactory Pro trial version www.pdffactory.com
F = {q0 ,q5 }
q0
F = {q0 ,q5 }
q5
q4
q5
q4
a
b
q1
q2
q3
q0
a
b
q1
q2
q3
* (q0 , ab ) = {q2 , q3 , q0 }
ab L(M )
aaba L (M )
73
F = {q0 ,q5 }
q5
q4
a
q0
74
a
b
q1
q5
q4
q2
q3
q0
q1
a
q2
q3
aba L( M )
75
76
Formally
The language accepted by NFA
w L(M )
is:
L( M ) = {w1, w2 , w3 ,...}
* (q0 , w)
qi
w
where
q0
qk
w
w
qk F
qk F
qj
(final state)
77
78
13
PDF created with pdfFactory Pro trial version www.pdffactory.com
Equivalence of Machines
For DFAs or NFAs:
Machine
if
M1
is equivalent to machine
M2
L ( M1 ) = L ( M 2 )
79
Example
L( M1 ) = {10} *
NFA
q1
q0
0, 1
machines
NFA
M2
0,1
q2
and
are equivalent
M2
0
M1
q0
q1
0, 1
q2
DFA
M2
q0
q1
q2
81
NFAs
M1
0,1
q1
0
Question:
L( M1 ) = L(M 2 ) = {10}*
q2
DFA
L( M 2 ) = {10} *
Since
M1
q0
80
82
DFAs ?
Question:
Same power?
Accept the same languages?
NFAs
DFAs ?
YES!
Same power?
Accept the same languages?
83
84
14
PDF created with pdfFactory Pro trial version www.pdffactory.com
We will prove:
Languages
accepted
by NFAs
Step 1
Languages
accepted
by DFAs
Languages
accepted
by NFAs
85
Step 2
NFA
M
q0
DFA
DFA
q1
q2
{q0 }
87
88
NFA
M
q0
DFA
{q0 }
NFA to DFA
a
a
q
q1
2
b
M
q0
NFA
86
NFA to DFA
a
Languages
accepted
by DFAs
Languages
accepted
by NFAs
Languages
accepted
by DFAs
NFA to DFA
a
a
q
q1
2
b
{q0 }
{q1, q2 }
{q1, q2 }
89
90
15
PDF created with pdfFactory Pro trial version www.pdffactory.com
NFA
M
q0
DFA
NFA to DFA
a
a
q
q1
2
b
NFA
q0
{q0 }
DFA
NFA to DFA
a
a
q
q1
2
b
{q0 }
{q1, q2 }
{q1, q2 }
91
NFA
NFA to DFA
a
M
q0
q1
92
NFA
M
q0
q2
NFA to DFA
a
L( M ) = L(M )
a
q
q
1
b
DFA
b
a
{q0 }
DFA
{q0 }
{q1, q2 }
{q1, q2 }
b
a, b
a, b
93
94
q0 , q1, q2 ,...
We want to convert it
to an equivalent DFA M
L( M ) = L (M )
95
96
16
PDF created with pdfFactory Pro trial version www.pdffactory.com
1.
Example
a
M
q0
q1
q0
q2
b
DFA
{q0 }
{q0}
97
98
NFA
Exampe
a
M
q0
q1
q2
b
* (q0 , a ) = {q1, q2 }
* (qi , a ),
* (q j , a ),
= {qi , qj ,..., qm }
DFA M
...
{q0 }
{q1, q2 }
({q0 }, a ) = {q1, q2 }
99
100
Example
a
M
q0
q1
q2
b
DFA
{q0 }
{q1, q2 }
101
a, b
102
17
PDF created with pdfFactory Pro trial version www.pdffactory.com
NFA
Example
a
M
q0
q1
q2
q1 F
b
If some
qj
{q0 }
b
a
{q1, q2 }
{q1, q2 } F
b
a, b
103
Take NFA
Theorem
Finally
We have proven
Then
104
and
Languages
accepted
by NFAs
are equivalent :
Languages
accepted
by DFAs
L( M ) = L(M )
105
106
We have proven
Languages
accepted
by NFAs
We have proven
Languages
accepted
by DFAs
Languages
accepted
by NFAs
Regular Languages
Regular Languages
107
Languages
accepted
by DFAs
Regular Languages
108
18
PDF created with pdfFactory Pro trial version www.pdffactory.com
We have proven
Languages
accepted
by NFAs
Regular Languages
Languages
accepted
by DFAs
Regular Languages
19
PDF created with pdfFactory Pro trial version www.pdffactory.com