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

Lect - 5,6 (Conversion of NFA To DFA)

Theory of Automata and Formal Languages
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Lect - 5,6 (Conversion of NFA To DFA)

Theory of Automata and Formal Languages
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

CS-352 TAFL

Equivalence of Machines
Conversion of NFA to DFA

Instructor: Yusra Arshad

Book: Prof. Sipser-MIT

1
Equivalence of Machines

Definition:

Machine M1 is equivalent to machine M 2

if L( M1 ) = L( M 2 )

Book: Prof. Sipser-MIT 2


Example of equivalent machines

NFA M1
L(M1 ) = {10} * 0
q0 q1
1

DFA M2 0,1
L(M 2 ) = {10} * 0
q0 q1 1 q2
1
0
Book: Prof. Sipser-MIT 3
Conversion of NFA to DFA: Example

Book: Prof. Sipser-MIT 4


Book: Prof. Sipser-MIT 5
Book: Prof. Sipser-MIT
Book: Prof. Sipser-MIT 7
Conversion NFA to DFA

Book: Prof. Sipser-MIT 8


Another Example

Book: Prof. Sipser-MIT 9


Book: Prof. Sipser-MIT 10
Another Example
Convert the following Non-Deterministic Finite Automata (NFA) to
Deterministic Finite Automata (DFA)

Book: Prof. Sipser-MIT 11


Transition Table of NFA

Book: Prof. Sipser-MIT 12


Transition table of DFA

Book: Prof. Sipser-MIT 13


Book: Prof. Sipser-MIT 14
Step 5

Book: Prof. Sipser-MIT 15


Final step

Book: Prof. Sipser-MIT 16


Equivalent DFA

Book: Prof. Sipser-MIT 17


Important points
• After conversion, the number of states in the
resulting DFA may or may not be same as NFA.
• The maximum number of states that may be
present in the DFA are 2Number of states in the NFA.
• In general, the following relationship exists
between the number of states in the NFA and
DFA-

Book: Prof. Sipser-MIT 18


Important points
•In the resulting DFA, all those states that
contain the final state(s) of NFA are treated as
final states.

Book: Prof. Sipser-MIT 19


Conversion of NFA to DFA
NFA M
a
q0 a q1  q2
b

DFA M
q0 

Book: Prof. Sipser-MIT 20


 * (q0 , a ) = {q1 , q2 }
NFA M a
q0 a q1  q2
b

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

Book: Prof. Sipser-MIT 21


 * (q0 , b ) =  empty set

NFA M a
q0 a q1  q2
b

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

 trap state
Book: Prof. Sipser-MIT 22
 (q1 , a ) = {q1 , q2 }
*

NFA M a  * (q2, a ) = 
q0 a q1  q2 union

b q1, q2 

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


Book: Prof. Sipser-MIT 23
 (q1 , b ) = {q0 }
*

NFA M a  * (q2, b ) = {q0 }


q0 a q1  q2
union

b q0 

a
DFA M b

q0  a
q1, q2 
b


Book: Prof. Sipser-MIT 24
NFA M a
q0 a q1  q2
b

a
DFA M b

q0  a
q1, q2 
b

 a, b trap state
Book: Prof. Sipser-MIT 25
END OF CONSTRUCTION

NFA M a
q0 a q1  q2 q1  F
b
a
DFA M b

q0  a
q1, q2 
q1, q2  F 
b

 a, b
Book: Prof. Sipser-MIT 26
General Conversion Procedure

Input: an NFA M

Output: an equivalent DFA M 


with L(M ) = L(M )

Book: Prof. Sipser-MIT 27


The NFA has states q0 , q1, q2 ,...

The DFA has states from the power set

, q0 , q1 , q0 , q1 , q1 , q2 , q3 , ....

Book: Prof. Sipser-MIT 28


Conversion Procedure Steps

step
1. Initial state of NFA: q0
 (q0 ,  ) = q0 ,
*

Initial state of DFA: q0 , 

Book: Prof. Sipser-MIT 29


Example
a  (q0 ,  ) = q0 
*

NFA M
q0 a q1  q2
b

DFA M
q0 

Book: Prof. Sipser-MIT 30


step
2. For every DFA’s state {qi , q j ,..., qm }

compute in the NFA


 * (qi , a )
Union
  * (q j , a )
= {qk , ql,..., qn }
...
  * (qm , a )

add transition to DFA


 ({qi , q j ,..., qm }, a ) = {qk , ql,..., qn }
Book: Prof. Sipser-MIT 31
Example  * (q0 , a) = {q1, q2}
NFA M
a
q0 a q1  q2
b

DFA M
q0  a
q1, q2 
 (q0 , a ) = q1, q2 
Book: Prof. Sipser-MIT 32
step
3. Repeat Step 2 for every state in DFA and
symbols in alphabet until no more states
can be added in the DFA

Book: Prof. Sipser-MIT 33


Example
NFA M a
q0 a q1  q2
b

a
DFA M b

q0  a
q1, q2 
b

 a, b
Book: Prof. Sipser-MIT 34
step
4. For any DFA state {qi , q j ,..., qm }

if some q j is accepting state in NFA

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


is accepting state in DFA

Book: Prof. Sipser-MIT 35


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

q0  a
q1, q2 
q1, q2  F 
b

 a, b
Book: Prof. Sipser-MIT 36

You might also like