0% found this document useful (0 votes)
23 views

Lesson 05 Introduction To Languages (NFA and RL)

The document discusses the equivalence of non-deterministic finite automata (NFAs) and deterministic finite automata (DFAs) and their ability to accept regular languages. It presents a proof that NFAs and DFAs have the same computational power by showing that any language accepted by an NFA is also accepted by a DFA, and vice versa, through an algorithm to convert an NFA to an equivalent DFA. The algorithm works by constructing the DFA's states as sets of NFA states, calculating the DFA transitions based on the NFA transitions, and determining final states based on the NFA's final states.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Lesson 05 Introduction To Languages (NFA and RL)

The document discusses the equivalence of non-deterministic finite automata (NFAs) and deterministic finite automata (DFAs) and their ability to accept regular languages. It presents a proof that NFAs and DFAs have the same computational power by showing that any language accepted by an NFA is also accepted by a DFA, and vice versa, through an algorithm to convert an NFA to an equivalent DFA. The algorithm works by constructing the DFA's states as sets of NFA states, calculating the DFA transitions based on the NFA transitions, and determining final states based on the NFA's final states.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 43

NFAs accept the Regular

Languages

Courtesy Costas Busch - RPI 1


Equivalence of Machines

Definition for Automata:

Machine M1 is equivalent to machine M 2

if L M 1   L M 2 

Courtesy Costas Busch - RPI 2


Example of equivalent machines
NFA M1
0
L M1   {10} *
q0 q1
1

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

Courtesy Costas Busch - RPI 5


Step 1

Languages
accepted  Regular
Languages
by NFAs

Proof: Every DFA is trivially an NFA

Any language L accepted by a DFA


is also accepted by an NFA
Courtesy Costas Busch - RPI 6
Step 2

Languages
accepted  Regular
Languages
by NFAs

Proof: Any NFA can be converted to an


equivalent DFA

Any language L accepted by an NFA


is also accepted by a DFA
Courtesy Costas Busch - RPI 7
Conversion NFA to DFA
a
NFA M
q a
0 q  q 1 2
b

DFA M
 q0 

Courtesy Costas Busch - RPI 8


 * (q0 , a )  {q1 , q2 }
M a
NFA
q0 a q1  q2
b

DFA M
 q0  a
 q1, q2 

Courtesy Costas Busch - RPI 9


 * (q0 , b )   empty set

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

Output: an equivalent DFA M 


with L M   L(M )

Procedure: subset construction

Courtesy Costas Busch - RPI 16


NFA to DFA: Formally

We are given an NFA M  (QN , ,  N , q0 , FN )

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 }

the DFA has 2n states in the power set of QN


i.e.
,  q0  ,  q1 ,  q1, q2  ,  q3 , q4 , q7  ,....

Courtesy Costas Busch - RPI 18


Procedure NFA to DFA

1. Initial state of NFA: q0


  q0 ,    q0 , 
*

Initial state of DFA: q0 , 

Courtesy Costas Busch - RPI 19


Example
M a
NFA
q0 a q1  q2
b

DFA M
 q0 

Courtesy Costas Busch - RPI 20


Procedure NFA to DFA
2. For every DFA’s state {qi , q j ,..., qm }

Compute in the NFA


 *  qi , a  Union
  * q j , a 
 {qi , qj ,..., qm
}
...
  *  qm , a 
Add transition to DFA
 {qi , q j ,..., qm }, a   {qi , qj ,..., qm
}
Courtesy Costas Busch - RPI 21
Example
M a
NFA
q0 a q1  q2
b
 * (q0 , a )  {q1, q2 }

DFA M 

 q0  a
 q1, q2 

   q0  , a    q1, q2 
Courtesy Costas Busch - RPI 22
Procedure NFA to DFA

Repeat Step 2 for all letters in alphabet, until


no more transitions can be added.

OR

Repeat Step 2 for every state in DFA and


symbols in alphabet until no more states can be
added in the DFA

Courtesy Costas Busch - RPI 23


Example
M a
NFA
q0 a q1  q2
b

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 }

If some q j is a final state in the NFA

Then, {qi , q j ,..., qm }


is a final state in the DFA

Courtesy Costas Busch - RPI 25


Example
M a
NFA
q0 a q1  q2 q1  F
b
a
DFA M b

 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  

Take arbitrary: w L(M )

We will prove: w  L(M )

Courtesy Costas Busch - RPI 28


w L(M )

M: q0 w qf

w   1 2  k
1 2 k
M: q0 qf

Courtesy Costas Busch - RPI 29


NOTE: symbol
i
qi qj

denotes a possible sub-path like

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 ,}

Courtesy Costas Busch - RPI 32


Proof by induction on |v|

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 ,}

Courtesy Costas Busch - RPI 34


Induction Step: | v | k  1
v  a1a2 ak ak 1  vak 1
   
v

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  vak 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  

We also need to show: L M   L M  

(proof is similar)

Courtesy Costas Busch - RPI 38


Activity
Time
NFAs vs. DFAs
NFAs vs. DFAs

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

You might also like