8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
1/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 1 of 21
Equivalence of NFAs and DFAs
Equivalence of NFAs and
DFAs
NFA and DFA Equivalence
Introduction
• Consider the following DFA M 1from the previous discussions.
M 1 accepts strings over the
alphabet = {0, 1} that start
with a 0 and end with a 1.
0 1q 0
0 1
q 2q 1
0
q 3
0, 1
1
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
2/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 2 of 21
Equivalence of NFAs and DFAs
• Consider now the followingNFA N 1 also from the previous
discussions.
N 1 also accepts strings over
the alphabet = {0, 1} thatstart with a 0 and end with 1.
• In other words, DFA M 1 and
NFA N 1 recognize the samelanguage. That is:
L(M 1) = L(N 1) = {w w starts
with 0 and ends with 1}
0 1q 0
0, 1
q 2q 1
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
3/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 3 of 21
Equivalence of NFAs and DFAs
• Two machines are equivalent
if they recognize the same
language. Therefore, M 1 is
equivalent to N 1.
• If a language is recognized by
a DFA, then there is an NFA
that will also recognize it. This
is because all DFAs are NFAs.
• The question now is:
If a language is recognized byan NFA, is there a DFA that
will also recognize it?
In other words, is there an
equivalent DFA for any NFA?
• To answer this question, a
procedure must be
constructed to convert any
NFA to its equivalent DFA.
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
4/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 4 of 21
Equivalence of NFAs and DFAs
Converting NFAs with noε
-Transitions into their Equivalent
DFA
• Recall that an NFA can be in
one or more states at any
given time.
• Consider NFA N 1 which has
three states q0, q1, and q2. At
any time, the NFA may be in:
1. state q0 only.
2. state q1 only.
3. state q2 only.
4. states q0 and q1.
5. states q0 and q2.
6. states q1 and q2.
7. states q0, q1, and q2.
8. dead state (stopped
processing).
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
5/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 5 of 21
Equivalence of NFAs and DFAs
• Observe that the possible
states the NFA can be in is thepower set (set of all subsets)
of its set of states Q. The
dead state is equivalent to the
null set.
• The DFA to be constructed
from this NFA will have a state
that will represent each of the
elements of the power set.
For example, the state in
which the NFA is in states q0and q1 will be represented by a
single state (that may be
called q01) in its equivalentDFA.
• If the NFA has n states, then
the equivalent DFA will have
2n states (number of states is
finite).
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
6/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 6 of 21
Equivalence of NFAs and DFAs
• The states of the equivalentDFA will then be
• The initial state of the NFA N 1is q0 so the initial state of the
DFA will also be q0.
NFA State DFA State
q0 q0q1 q1
q2 q2
q0, q1 q01
q0, q2 q02
q1, q2 q12
q0, q1, q2 q012
Dead State qdead
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
7/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 7 of 21
Equivalence of NFAs and DFAs
• The final state of NFA N 1 is q2.
This means that the NFA will
be in a final state if q2 is
included in the subset.
Therefore, the final states for
the DFA are q2, q02, q12, and
q012.
• Take note that not all of the
states of the equivalent DFAare reachable from the start
state. It is thus possible that
some of these states will
eventually be removed.
The states that will be
removed will be determined
upon the construction of the
transition function of the DFA.
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
8/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 8 of 21
Equivalence of NFAs and DFAs
• Construction of the transition
function for the equivalent DFA
for NFA N 1
Starting at state q0:
If input = 0, the NFA will go
to state q1. For the DFA,
this will be state q1.
If input = 1, the NFA will go
to a dead state. For the
DFA, this will be state
qdead
.
The next states to be analyzed
are states q1 and qdead (the
states reachable from q0).
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
9/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 9 of 21
Equivalence of NFAs and DFAs
From state q1:
If input = 0, the NFA will be
at state q1 only. For the
DFA, this will be state q1.
If input = 1, the NFA will be
in states q1 and q2. For the
DFA, this will be state q12.
From state qdead:
The NFA will stay at its
dead state regardless of
the input symbol received.
So will the DFA.
The next state to be analyzed
is state q12 since it is
reachable from state q0
(through state q1).
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
10/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 10 of 21
Equivalence of NFAs and DFAs
From state q12:
If input = 0, the copy of the
NFA at q1 stays at q1. The
copy at q2 will stop
processing. So the NFA
will be at state q1 only. For
the DFA, this will be state
q1.
If input = 1, the copy of the
NFA at state q1 will go to
states q1 and q2. The the
copy at q2
will stop
processing. So the NFA
will be at states q1 and q2.
For the DFA, this will be
state q12.
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
11/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 11 of 21
Equivalence of NFAs and DFAs
• Since all the states reachablefrom q0 have been analyzed,
the transition table will be
• Observe that states q2, q01,
q02, and q012 are not reachable
from state q0. These can
therefore be removed from the
transition table.
0 1
q0 q1 qdead
q1 q1 q12
q2
q01
q02
q12 q1 q12
q012
qdead qdead qdead
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
12/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 12 of 21
Equivalence of NFAs and DFAs
• The final transition function willthen be
• The state diagram of theequivalent DFA is
0 1
q0 q1 qdead
q1 q1 q12
q12 q1 q12
qdead qdead qdead
0 1
q 0
0 1
q 12q 1
0
q dead
0, 1
1
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
13/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 13 of 21
Equivalence of NFAs and DFAs
• As another example, consider
the following NFA N 2.
N 2 accepts strings over the
alphabet = {0, 1} that containthe substring 11.
Since the NFA has three
states, the possible states itcan assume are q0 only, q1only, q2 only, q0 and q1, q0 and
q2, q1 and q2, q1 and q2, and
q3, and the dead state.
1q 0
0, 1
q 2q 1
0, 1
1
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
14/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 14 of 21
Equivalence of NFAs and DFAs
The states of the equivalent
DFA will then be
The initial state of the NFA is
q0 so the initial state of the
DFA will also be q0.
NFA State DFA State
q0 q0
q1 q1
q2 q2
q0, q1 q01
q0, q2 q02
q1, q2 q12
q0, q1, q2 q012
Dead State qdead
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
15/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 15 of 21
Equivalence of NFAs and DFAs
The final state of the NFA is
q2. This means that the NFAwill be in a final state if q2 is
included in the subset.
Therefore, the final states for
the DFA are q2, q02, q12, andq012.
Starting at state q0:
If input = 0, the NFA will
stay at q0. For the DFA,
this will be state q0.
If input = 1, the NFA will beat q0 and q1. For the DFA,
this will be state q01.
The next state to be analyzed
is state q01.
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
16/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 16 of 21
Equivalence of NFAs and DFAs
From state q01:
If input = 0, the copy of the
NFA at state q0 will stay at
q0. The copy at q1 will stop
processing. The NFA willthen be at state q0 only.
For the DFA, this is state
q0.
If input = 1, the copy of theNFA at state q0 will be at
states q0 and q1. The copy
at state q1 will go to state
q2. The NFA will then be
at states q0, q1, and q2.For the DFA, this is state
q012.
The next state to be analyzed
is state q012.
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
17/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 17 of 21
Equivalence of NFAs and DFAs
From state q012:
If input = 0, the copy of the
NFA at q0 will stay at q0,
the copy at q1 will stopprocessing, and the copy
at q2 will stay at q2. The
NFA will then be at states
q0 and q2. For the DFA,
this is state q02.
If input = 1, the copy of the
NFA at q0 will be at state q0and q1, the copy at q1 will
go to state q2, and the copyof q2 will stay at q2. The
NFA will then be at states
q0, q1, and q2. For the
DFA, this is state q012.
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
18/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 18 of 21
Equivalence of NFAs and DFAs
The next state to be analyzed
is state q02.
From state q02:
If input = 0, the copy of the
NFA at q0 will stay at q0.
The copy at q2 will stay at
q2. The NFA will then be
at states q0 and q2. For theDFA, this is state q02.
If input = 1, the copy of the
NFA at q0 will be at states
q0 and q1. The copy at q2will stay at state q2. The
NFA will then be at states
q0, q1, and q2. For the
DFA, this is state q012.
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
19/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 19 of 21
Equivalence of NFAs and DFAs
• Since all the states reachable
from q0 had been analyzed,
the transition function will be
• Observe that states q1, q2, q12,
and qdead are not reachable
from state q0. These can
therefore be removed from the
transition table.
0 1
q0 q0 q01q1
q2
q01 q0 q012
q02 q02 q012
q12
q012 q02 q012
qdead
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
20/21
Theory of Computation (With Automata Theory)
* Property of STI
Page 20 of 21
Equivalence of NFAs and DFAs
• The final transition table willthen be
• The state diagram of the
equivalent DFA is
0 1
q0 q0 q01
q01 q0 q012
q02 q02 q012
q012 q02 q012
1
q 0
0 1
q 012q 01
0
1
0 q 02
0 1
8/21/2019 MELJUN CORTES Automata Lecture Equivalence of Nfas and Dfas Part 1 2
21/21
Theory of Computation (With Automata Theory)
* Property of STI Equivalence of NFAs and DFAs
• Additional Exercise
Construct the equivalent DFAfor the following NFA.
0q 0
0, 1
q 2q 10
Top Related