THEORY OF
COMPUTATION
(TOC)
Aravendra Sharma
Asst. Professor
Dept. of CSA
ITM University, Gwalior
CONVERSION
OF NFA To
DFA
Conversion of NFA to
DFA
• An NFA can have zero, one or more than one move from
a given state on a given input symbol. An NFA can also
have NULL moves (moves without input symbol).
• On the other hand, DFA has one and only one move from
a given state on a given input symbol.
• Both NFA and DFA are equally power.
Conversion of NFA to
DFA
There is an NFA N < Q, ∑, q0, δ, F > which recognizes a
language L. Then the DFA D < Q’, ∑, q0, δ’, F’ > can be constructed for
language L as:
•Step 1: Initially Q’ = ɸ.
•Step 2: Add q0 to Q’.
•Step 3: For each state in Q’, find the possible set of states for
each input symbol using transition function of NFA. If this set of states is
not in Q’, add it to Q’.
•Step 4: Final state of DFA will be all states with contain F (final states of
NFA)
Conversion of NFA to
Example-1
DFA
Conversion of NFA to
Example-1
DFA
Following are the various parameters for
NFA. Q = { q0, q1, q2 }
∑ = ( a, b )
F = { q2 }
δ = (Transition Function of NFA)
Conversion of NFA to
Example-1
DFA
Conversion of NFA to
Example-1
DFA
•Step 1: Q’ = ɸ
• Step 2: Q’ = {q0}
•Step 3: For each state in Q’, find the states for each input
symbol. Currently, state in Q’ is q0, find moves from q0 on input symbol
a and b using transition function of NFA and update the transition
table of DFA.
Conversion of NFA to
Example-1
DFA
Now { q0, q1 } will be considered as a single state. As its entry is not in
Q’, add it to Q’.
So Q’ = { q0, { q0, q1 } }
Conversion of NFA to
Example-1
DFA
Now, moves from state { q0, q1 } on different input symbols are
not present in transition table of DFA, we will calculate it like:
δ’ ( { q0, q1 }, a ) = δ ( q0, a ) ∪ δ ( q1, a ) = { q0, q1 }
δ’ ( { q0, q1 }, b ) = δ ( q0, b ) ∪ δ ( q1, b ) = { q0, q2 }
Conversion of NFA to
Example-1
DFA
•Now { q0, q2 } will be considered as a single state. As its entry is not in
Q’, add it to Q’.
So Q’ = { q0, { q0, q1 }, { q0, q2 } }
•Now, moves from state {q0, q2} on different input symbols are
not present in transition table of DFA, we will calculate it like:
δ’ ( { q0, q2 }, a ) = δ ( q0, a ) ∪ δ ( q2, a ) = { q0, q1 }
δ’ ( { q0, q2 }, b ) = δ ( q0, b ) ∪ δ ( q2, b ) = { q0 }
•Now we will update the transition table of DFA.
Conversion of NFA to
Example-1
DFA
•Now we will update the transition table of DFA.
• As there is no new state generated, we are done with the conversion.
Final state of DFA will be state which has q2 as its component i.e.,
{ q0, q2 }
Conversion of NFA to
Example-1
DFA
Following are the various parameters for DFA.
Q’ = { q0, { q0, q1 }, { q0, q2 } }
∑ = ( a, b )
F = { { q0, q2 } }
The final DFA for above NFA has been shown in Figure
Conversion of NFA to
Example-2
DFA
Sol:
State 0 1
→q0 q0 q1
q1 q1, q2 q1
q2 q2 q1, q2
Conversion of NFA to
Example-2
DFA
•Step 1: Q’ = ɸ
• Step 2: Q’ = {q0}
•Step 3: For each state in Q’, find the states for each input symbol.
•Currently, state in Q’ is q0, find moves from q0 on input symbol a and b
using transition function of NFA and update the transition table of
DFA.
Conversion of NFA to
Example-2
DFA
State 0 1
→{q0} {q0} {q1}
• Now we will obtain δ' transition for state q0.
δ'([q0], 0) = [q0]
δ'([q0], 1) = [q1]
• As its entry is not in Q’, add it to Q’. So Q’ = { q0,
q1 }
Conversion of NFA to
Example-2 DFA
•Now, moves from state {q1}.The δ' transition for state q1 is obtained as:
δ'([q1], 0) = [q1, q2] (new state generated)
δ'([q1], 1) = [q1]
•Now { q1, q2 } will be considered as a single state. As its entry is not in
Q’, add it to Q’. So Q’ = { q0, q1, { q1, q2 } }.
State 0 1
→{q0} {q0} {q1}
{q1} {q1, q2} {q1}
Conversion of NFA to
Example-2 DFA
Now, moves from state { q1, q2 } on different input are not
symbols
δ'([q1, q2], 0) = δ(q1, 0) ∪ δ(q2, 0)
present in transition table of DFA, we will calculate it like:
= {q1, q2} ∪ {q2}
= [q1, q2]
δ(q1, 1) ∪ δ(q2, 1)
δ'([q1, q2], 1) =
= {q1} ∪ {q1, q2}
= {q1, q2}
= [q1, q2]
Conversion of NFA to
Example-2 DFA
The state {q1, q2} is the final state as well because it contains a final state
q2. The transition table for the constructed DFA will be:
State 0 1
→{q0} {q0} {q1}
{q1} {q1, q2} {q1}
{q1, q2} {q1, q2} {q1, q2}
Conversion of NFA to
Example-2 DFA
The Transition diagram will
be:
Assignment
Assignment Question
Convert the NFA to
DFA.
References
• Hopcroft & Ullman “Introduction to Automata
theory, languages & Computation” , Narosha Publishing
• house.
Lewish Papadimutrau “Theory of Computation” ,
Prentice Hall of India, New Delhi.
• Mishra & Shekhar of
Chander(Automate, Language
Science “Theory& Computations),
Computer
PHI.