You are on page 1of 32

NFA to Minimized DFA

RE to DFA
• To convert RE to NFA use – Thompson’s algorithm
• To convert NFA to DFA use – Subset Construction algorithm
• To minimize the obtained DFA use – Tabulation method (also called
Mark/Reduce procedure)
Subset construction algorithm
Step 1: Find the λ-closure of all the states
Step 2: Let the λ-closure of the initial state be named as A
Step 3: Now find the transitions of each input symbol on this state A.
Then, find the λ-closure of the above set and name it as A if it appears
to be same otherwise give a new name as B.
Step 4: Repeat Step 3 for each of the new states added until there are
no new states in the queue.
Step 5: Convert the above representation to a DFA. The initial state of
the DFA will be A. Mark the final states of DFA.
λ-closure
• Lambda Closure, λ(S), for a set of states S is defined as:
• Every element of S in an element of λ(S)
• For any q λ(S), every element of (q, λ) is in λ(S)
• No other element of Q are in λ(S)
Example 1
• Convert the RE (a+b)*abb to a minimized DFA

λ-closure(0) = {0, 1, 2, 4, 7} λ-closure(4) = {4} λ-closure(8) = {8}


λ-closure(1) = {1, 2, 4} λ-closure(5) = {1, 2, 4, 5, 6, 7} λ-closure(9) = {9}
λ-closure(2) = {2} λ-closure(6) = {1, 2, 4, 6, 7} λ-closure(10) = {10}
λ-closure(3) = {1, 2, 3, 4, 6, 7} λ-closure(7) = {7}
Example 1
λ-closure(0) = {0, 1, 2, 4, 7} – A
λ-closure(ẟ(A, a)) = λ-closure(3, 8) = {1, 2, 3, 4, 6, 7, 8} – B
λ-closure(ẟ(A, b)) = λ-closure(5) = {1, 2, 4, 5, 6, 7} – C
λ-closure(ẟ(B, a)) = λ-closure(3, 8) = {1, 2, 3, 4, 6, 7, 8} – B
λ-closure(ẟ(B, b)) = λ-closure(5, 9) = {1, 2, 4, 5, 6, 7, 9} – D
λ-closure(ẟ(C, a)) = λ-closure(3, 8) = {1, 2, 3, 4, 6, 7, 8} – B
λ-closure(ẟ(C, b)) = λ-closure(5) = {1, 2, 4, 5, 6, 7} – C
λ-closure(ẟ(D, a)) = λ-closure(3, 8) = {1, 2, 3, 4, 6, 7, 8} – B
λ-closure(ẟ(D, b)) = λ-closure(5, 10) = {1, 2, 4, 5, 6, 7, 10} – E
λ-closure(ẟ(E, a)) = λ-closure(3, 8) = {1, 2, 3, 4, 6, 7, 8} – B
λ-closure(ẟ(E, b)) = λ-closure(5) = {1, 2, 4, 5, 6, 7} – C
Example 1 – Final DFA
States a b
-> A B C a
B B D
C B C b
D B E a B D
*E B C
a
b
A a a
b C E
b

b
DFA Minimization - Tabulation method
• Are All states reachable from initial state?
• Yes – include that state for next step
• No – remove that state
Eg-1: Eg-2:

• All states are reachable

• q5 state is not reachable from initial state,


so remove q5 from the further procedure
Mark/Reduce Procedure
DFA Minimization - Tabulation method
Step-1: Draw a table for all pairs of states (P,Q)
Step-2: Mark all pairs where P F and Q F (vice-versa also)
Step-3: If there are any unmarked pairs (P, Q) such that [ (P,x), (Q, x)]
is marked, then mark [P, Q] where ‘x’ is an input symbol
Step-4: Repeat Step-3, until no more markings can be made
Step-5: Combine all the unmarked pairs and make them a single state
in the minimized DFA
a
DFA Minimization - Tabulation method
B b D
a
a
Table Creation: A
a a
b
b C E
b
A A
b
B B
C C
D D
E E
A B C D E A B C D E

Consider the pair (B, C)


All pairs have multiple locations
DFA
a
Minimization – Tabulation Method
B b D Mark/Reduce Procedure
a States a b
a
A b -> A B C
a a B
B B D
b C E
b C B C
D B E C
b
*E B C
D

Pair – (AC) A B C D
Minimized DFA
States a b States a b
-> A B C -> A B A
B B D B B D
a
C B C D B E
D B E *E B A b b
a B D
*E B C
a
A b
a
b E
Example 2
• Find the minimal DFA for abb(a+b)*
Example 2

λ-closure(0) = {0} λ-closure(1) = {1} λ-closure(2) = {2}


λ-closure(3) = {3, 4, 5, 7, 10} λ-closure(4) = {4, 5, 7} λ-closure(5) = {5}
λ-closure(6) = {4, 5, 6, 7, 9, 10} λ-closure(7) = {7} λ-closure(8) = {4, 5, 7, 8, 9, 10}
λ-closure(9) = {4, 5, 7, 9, 10} λ-closure(10) = {10}
Example 2 – Subset Alg.
• λ-closure(0) = {0} - A
• λ-closure(ẟ(A, a)) = λ-closure(1) = {1} – B
• λ-closure(ẟ(A, b)) = φ
• λ-closure(ẟ(B, a)) = φ
• λ-closure(ẟ(B, b)) = λ-closure(2) = {2} – C
• λ-closure(ẟ(C, a)) = φ
• λ-closure(ẟ(C, b)) = λ-closure(3) = {3, 4, 5, 7, 10} – D
Example 2

• λ-closure(ẟ(D, a)) = λ-closure(6) = {4, 5, 6, 7, 9, 10} – E


• λ-closure(ẟ(D, b)) = λ-closure(8) = {4, 5, 7, 8, 9, 10} – F
• λ-closure(ẟ(E, a)) = λ-closure(6) = {4, 5, 6, 7, 9, 10} – E
• λ-closure(ẟ(E, b)) = λ-closure(8) = {4, 5, 7, 8, 9, 10} – F
• λ-closure(ẟ(F, a)) = λ-closure(6) = {4, 5, 6, 7, 9, 10} – E
• λ-closure(ẟ(F, b)) = λ-closure(8) = {4, 5, 7, 8, 9, 10} – F
Example 2 - Minimization
States a b B
-> A B φ
B φ C
C
C φ D
*D E F
D
*E E F
*F E F
E

Pairs F
{{DE}{DF}}
{EF} => {DEF} A B C D E
Example 2 – Minimized DFA
States a b

-> A B φ
a, b
B φ C

C φ D T
*D D D a, b
b a
a
a b b
A B C D
Example 3
• Convert to minimized DFA
1
0
0, 1 0, 1
q0 q1 q2

• λ-closure(q0) = {q0}
• λ-closure(q1) = {q1}
• λ-closure(q2) = {q2}
Example 3
• λ-closure(q0) = {q0} – A
• λ-closure(ẟ(A, 0)) = λ-closure(q0,q1} = {q0,q1} – B
• λ-closure(ẟ(A, 1)) = λ-closure(q1} = {q1} – C
• λ-closure(ẟ(B, 0)) = λ-closure(q0,q1,q2} = {q0,q1,q2} – D
• λ-closure(ẟ(B, 1)) = λ-closure(q1,q2} = {q1,q2} – E
• λ-closure(ẟ(C, 0)) = λ-closure(q2} = {q2} – F
• λ-closure(ẟ(C, 1)) = λ-closure(q2} = {q2} – F
• λ-closure(ẟ(D, 0)) = λ-closure(q0,q1,q2} = {q0,q1,q2} – D
• λ-closure(ẟ(D, 1)) = λ-closure(q1,q2} = {q1,q2} - E
Example 3
• λ-closure(ẟ(E, 0)) = λ-closure(q2} = {q2} – F
• λ-closure(ẟ(E, 1)) = λ-closure(q2} = {q2} – F States 0 1
• λ-closure(ẟ(F, 0)) = φ -> A B C

• λ-closure(ẟ(F, 1)) = λ-closure(q2} = {q2} - F *B D E


*C F F
*D D E
*E F F
F φ F
B
Example 3
C

E
States 0 1
-> A B C F
*B D E
*C F F
A B C D E
*D D E Pairs:
*E F F
F φ F
(BD), (CE)
Example 3 – Minimized DFA
States 0 1 States 0 1
-> A B C -> A X Y
*B D E *X X Y
*C F F *Y F F
*D D E F φ F
0 0, 1
*E F F
F φ F X
0
F
• Let (BD) be X A 1
0, 1
• Let (CE) be Y 1 Y
Example 4
• Find the minimized DFA for the given NFA
0 1 1

q0 q1
q1 q2

0, λ 0, 1

• λ-closure(q0) = {q0, q1}


• λ-closure(q1) = {q1}
• λ-closure(q2) = {q2}
Example 4
• λ-closure(q0) = {q0, q1} - A
• λ-closure(ẟ(A, 0)) = λ-closure(q0, q1, q2) = {q0, q1, q2} – B
• λ-closure(ẟ(A, 1)) = λ-closure(q1, q2) = {q1, q2} – C
• λ-closure(ẟ(B, 0)) = λ-closure(q0, q1, q2) = {q0, q1, q2} – B
• λ-closure(ẟ(B, 1)) = λ-closure(q1, q2) = {q1, q2} – C
• λ-closure(ẟ(C, 0)) = λ-closure(q0, q2) = {q0, q1, q2} – B
• λ-closure(ẟ(C, 1)) = λ-closure(q1, q2) = {q1, q2} - C
Example 4
States 0 1 B

->* A B C
C All pairs are
indistinguishable
*B B C So, {ABC} is a single
state
A B
*C B C

0, 1

X
Example 5 - Minimize the given DFA
States 0 1 States 0 1
q1
-> q0 q1 q3 -> q0 X X
q1 q2 q4 X X q4
q2 q1 q4 *q4 q4 q4 q2
q3 q2 q4
*q4 q4 q4 q3

• First draw the DFA and check if all q4


the states are reachable from start
state
q0 q1 q2 q3
• The sets are {q1, q2, q3} and {q2,
q3}.
• So, {q1, q2, q3} can be combined
into one state
Exercises – NFA to Minimized DFA
b c
1. a

A B X
C
λ λ

1
0
2.
A B C
0,1 0,1
Exercises – NFA to Minimized DFA
3. a
b a, b

A B X
C
a, λ b, λ

b, λ

4. RE ab*a(a+b)
5. RE (0+1)+(0+1)*
6. 𝐿 = 𝑎𝑛 𝑏 𝑚 ∶ n ≥ 1, m ≥ 2
7. 𝐿 = 𝑎𝑛 b: n ≥ 1} ⋃ {𝑏 𝑛 a ∶ n ≥ 1
Exercises – Minimize the DFA
8. States 0 1 9.
-> A B F
B G C
*C A C
D C G
E H F
F C G
G G E
H G C
Exercises
10.

You might also like