5. Section 2.3
5. Section 2.3
1
Equivalence of Machines
if L M1 L M 2
2
Example of equivalent machines
NFA M1
LM1 {10} * 0
q0 q1
1
DFA M2 0,1
LM 2 {10} * 0
q0 q1 1 q2
1
0
3
We will prove:
Languages
Regular
accepted
Languages
by NFAs
Languages
accepted
by DFAs
NFAs and DFAs have the
same computation power
4
NFA to DFA: Remarks
We want to convert it
to an equivalent DFA M
Languages
accepted Regular
Languages
by NFAs
Languages
accepted Regular
Languages
by NFAs
8
Procedure to convert NFA to DFA
Step 1.
Initial state of NFA: q0
9
Procedure NFA to DFA
Step 2. For every DFA’s state
{qi , q j ,..., qm }
Compute in the NFA
* qi , a ,
* q j , a , {qi , qj ,..., qm
}
...
Add transition to DFA
{qi , q j ,..., qm }, a {qi , qj ,..., qm
}
10
Procedure NFA to DFA
11
Procedure NFA to DFA
Step 3.
For any DFA state {qi , q j ,..., qm }
q0 , q1, q2 ,...
13
Example (Step 1)
NFA M a
q0 a q1
q 2
b
DFA M
q0
14
Example (Step 2)
NFA M a
q0 a q q
1 2
b
* (q0 , a ) {q1, q2 }
DFA M
q0 a
q1, q2
q0 , a q1, q2
15
Example (step 2)
NFA M a
q0 a q q
1 2
b
a
DFA M b
q0 a
q1, q2
b
a, b
16
Example (step 3)
NFA M a
q0 a q q
1 2 q1 F
b
a
DFA M b
q0 a
q1, q2
b q1, q2 F
a, b
17
By the process of construction,
If there exists a walk on a string, w,
from q0 to in the NFA M,
Construct DFA M
20
Another Example
DFA M
21
22
Homework 2.3
I) Do exercises : #1, #2, #3, #4
23
CS3186
Reduction in number of
states of a DFA
Section 2.4
24
Equivalent or Indistinguishable States
Definition: Two states p and q are equivalent (or
indistinguishable), if, for every string w * ,
transition *( p , w ) ends in an accepting state if and
only if *( q , w) does. There are efficient algorithms
available for computing the sets of equivalent states
of a given DFA.
25
Minimization Technique for DFA
26
DFA-> Minimum DFA
Minimization Algorithm:
Step 0: Remove from M1 the dead states and the
states not reachable from the start state, if there
are any. Any transitions to a dead state become
undefined.
A state is a dead state if it is not an accepting state
and has no out-going transitions except to itself.
Step 2: Initialize k = 1
27
Step 3: Find Pk by partitioning the different
sets of Pk-1. In each set of Pk-1, we will take
all possible pair of states. If two states of a
set are distinguishable, we will split the sets
into different sets in Pk.
Note: Two states ( qi, qj ) are distinguishable in partition Pk if
for any input symbol a, δ ( qi, a ) and δ ( qj, a ) are in different
sets in partition Pk-1.
Step 4: Stop when Pk = Pk-1 (No change in
partition)
Step 5: All states of one set are merged into
one state. No. of states in minimized DFA
will be equal to no. of sets in Pk.
Note: The initial state will be the set that contains the given
initial state. Similarly the sets that contain any of the initial
final states will be the final state of the minimal DFA 28
Example
29
Example
Step 1. P0 will have two sets of states. One set will
contain q1, q2, q4 which are final states of DFA and
another set will contain remaining states.
So P0 = { { q1, q2, q4 }, { q0, q3, q5 } }.
30
i) For set { q1, q2, q4 } :
31
ii) For set { q0, q3, q5 } :
33
iii)For set { q1, q2, q4 } :
34
iv)For set { q0, q3 } :
35
v) For set { q5 }:
Since we have only one state in this set, it can’t
be further partitioned.
37
Homework 2.4
I) Do exercises : #1, #2
38
Homework 2.4
II)
39