You are on page 1of 14

School of Engineering & Computer Science

Independent University, Bangladesh (IUB)

NFA to DFA conversion

M Ashraful Amin, PhD


NFAs are as powerful as DFAs

• An NFA can do everything a DFA can do


• How about the other way?

YES
Every NFA can be converted into
a DFA for the same language.
NFA → DFA in two easy steps

➊ Eliminate -transitions

➋ Convert simplified NFA


We do this first
NFA → DFA: intuition

0, 1

1 0
NFA: q q q

0 0

1 0
DFA: q q0 or q1 q0 or q2

1 1
NFA → DFA: intuition

0, 1

1 0
NFA: q q q

0 0

1 0
DFA: q {q0, q1} {q0, q2}

1 1
NFA → DFA: states
0, 1

1 0
NFA: q q q

DFA: {q0} {q0, q1}

 {q1} {q0, q2} {q0, q1, q2}

{q2} {q1, q2}

DFA has a state for every subset of NFA states


NFA → DFA: transitions
0, 1

1 0
NFA: q q q

0 1
1
DFA: {q0} {q0, q1}
0, 1 1
0 1
0
1
 {q1} {q0, q2}
0
{q0, q1, q2}

0, 0
1
0
{q2} {q1, q2}

1
NFA → DFA: accepting states
0, 1

1 0
NFA: q q q

0 1
1
DFA: {q0} {q0, q1}
0, 1 1
0 1
0
1
 {q1} {q0, q2}
0
{q0, q1, q2}

0, 0
1
0
{q2} {q1, q2}

NFA accepts if it contains a DFA final state


NFA → DFA: dead state elimination
0, 1

1 0
NFA: q q q

0 1
1
DFA: {q0} {q0, q1}
0, 1 1
0 1
0
1
 {q1} {q0, q2}
0
{q0, q1, q2}

0, 0
1
0
{q2} {q1, q2}

At the end, you can eliminate the unreachable states


General method

NFA DFA
states q0, q1, …, qn q0}, {q1}, {q0,q1}, …, {q0,…,qn}
one for each subset of states in the NFA

initial state q0 q0}

transitions  ’({qi1,…,qik}, a) =
(qi1, a) ∪…∪ (qik, a)
accepting FQ F’ = {S: S contains some state in F}
states
NFA → DFA in two easy steps

➊ Eliminate -transitions

➋ Convert simplified NFA ✔


Eliminating -transitions
, 1 0
q0 q1  q2
NFA:
0

NFA without s:

0 1
q0 {q0, q1, q2} {q1, q2}
q1 {q0, q1, q2} 
q2  

Accepting states: q2 , q1, q0


Eliminating -transitions
, 1 0
q0 q1  q2
NFA:
0

new NFA: 0 1
q0 {q0, q1, q2} {q1, q2}
q1 {q0, q1, q2} 
q2  

0 0
0, 1 0
q0 q1 q2
0
0, 1
Eliminating -transitions
• Paths with s are replaced by a single transition
q4

q5  q0 a q2  q0  q3 q3 a
 q5

a
q5 a q3 q3

• States that can reach final state by  are all accepting

q9 q7  q3  q2

You might also like