Lesson 05 Introduction To Languages (NFA and RL)
Lesson 05 Introduction To Languages (NFA and RL)
Languages
if L M 1 L M 2
DFA M2 0,1
0
L M 2 {10} *
q0 q1 1 q2
1
0
Courtesy Costas Busch - RPI 3
We will prove:
Languages
Regular
accepted
Languages
by NFAs
Languages
accepted
by DFAs
NFAs and DFAs have the
same computation power
Courtesy Costas Busch - RPI 4
Proof: we only need to show
Languages
accepted Regular
Languages
by NFAs
AND
Languages
accepted Regular
Languages
by NFAs
Languages
accepted Regular
Languages
by NFAs
Languages
accepted Regular
Languages
by NFAs
DFA M
q0
DFA M
q0 a
q1, q2
M a
NFA
q0 a q1 q2
b
DFA M
q0 a
q1, q2
b
trap state
Courtesy Costas Busch - RPI 10
(q1 , a ) {q1 , q2 }
*
M a * (q2 , a )
NFA
q0 a q1 q2 union
b q1, q2
a
DFA M
q0 a
q1, q2
b
Courtesy Costas Busch - RPI 11
(q1 , b ) {q0 }
*
M a * (q2 , b ) {q0 }
NFA
a union
q0 q1 q2
b q 0
b a
DFA M
q0 a
q1, q2
b
Courtesy Costas Busch - RPI 12
M a
NFA
q0 a q1 q2
b
b a
DFA M
q0 a
q1, q2
b
a, b trap state
Courtesy Costas Busch - RPI 13
END OF CONSTRUCTION
M a
NFA
q0 a q1 q2 q1 F
b
a
DFA M b
q0 a
q1, q2
q1, q2 F
b
a, b
Courtesy Costas Busch - RPI 14
Convert NFA to DFA
a
NFA M
q a
0 q q 1 2
b
L M L(M )
a
DFA M b
q0 a
q1, q2
b
a, b
Courtesy Costas Busch - RPI 15
General Conversion Procedure
Input: an NFA M
We want to convert it
M (QD , , D , {q0 }, FD )
to an equivalent DFA
With
L M L(M )
Courtesy Costas Busch - RPI 17
If the NFA has n states
QN {q0 , q1 , q2 ,..., qn }
DFA M
q0
DFA M
q0 a
q1, q2
q0 , a q1, q2
Courtesy Costas Busch - RPI 22
Procedure NFA to DFA
OR
b a
DFA M
q0 a
q1, q2
b
a, b
Courtesy Costas Busch - RPI 24
Procedure NFA to DFA
3. For any DFA state {qi , q j ,..., qm }
q0 a
q1, q2
b q1, q2 F
a, b
Courtesy Costas Busch - RPI 26
Lemma:
If we convert NFA M to DFA M
then the two automata are equivalent:
L M L M
Proof:
We only need to show: L M L M
AND
L M L M
First we show: L M L M
M: q0 w qf
w 1 2 k
1 2 k
M: q0 qf
symbol
i
qi qj
We will show that if w L(M )
w 1 2 k
1 2 k
M: q0 qf
1 2 k
M:
{q0 , } {q f ,}
w L(M )
Courtesy Costas Busch - RPI 31
More generally, we will show that if in M:
(arbitrary string) v a1a2 an
a1 a2 an
M: q0 qi qj ql qm
a1 a2 an
M:
{q0 , } {qi ,} {q j ,} {ql ,} {qm ,}
Induction Basis: v a1 |v | 1
a1
M: q0 qi
a1
M:
{q0 , } {qi ,}
is true by construction of M
Courtesy Costas Busch - RPI 33
Induction hypothesis: 1 | v | k
v a1a2 ak
a1 a2 ak
M: q0 qi qj qc qd
a1 a2 ak
M:
{q0 , } {qi ,} {q j ,} {qc ,} {qd ,}
a1 a2 ak
M: q0 qi qj qc qd
v
a1 a2 ak
M:
{q0 , } {qi ,} {q j ,} {qc ,} {qd ,}
v
Courtesy Costas Busch - RPI 35
Induction Step: | v | k 1
v a1a2 ak ak 1 vak 1
v
a1 a2 ak ak 1
M: q0 qi qj qc qd qe
v
a1 a2 ak ak 1
M:
{q0 , } {qi ,} {q j ,} {qc ,} {qd ,} {qe ,}
v
Courtesy Costas Busch - RPI 36
Therefore if w L(M )
w 1 2 k
1 2 k
M: q0 qf
1 2 k
M:
{q f ,}
{q0 , }
w L(M )
Courtesy Costas Busch - RPI 37
We have shown: L M L M
(proof is similar)
What is non-determinism?
Which is useful?
Which is powerful?
40
•NFAs are interesting because we can
express languages easier than DFAs
NFA M1 DFA M2 a
q2
q0 a q1
a
q0 a q1
L( M1 ) = {a} L( M 2 ) = {a}
Courtesy Costas Busch - RPI 41
42
43