Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

L6- ToC

NFA to DFA Conversion

Course Instructors:
Div 1: Praveen Pawar (Div 1)
Div 2: Jibi Abraham (Div 2)

1
DFA and NFA
 DFA
 For every string x, there is a unique path from
initial state and associated with x.
x

 x is accepted if and only if this path ends at a final


state.
 NFA
 For any string x, there may exist none or more
than one path from initial state and associated with
x.
NFA
 DFA:: δ: Q x Σ → Q

 NFA:: δ: Q x Σ → 2Q

In an NFA, possible
Polling - 1
 Which of the following option is correct?
a) NFA is slower to process and its
representation uses more memory than DFA
b) DFA is faster to process and its
representation uses less memory than NFA
c) NFA is slower to process and its
representation uses less memory than DFA
d) DFA is slower to process and its
representation uses less memory than NFA

4
DFA – NFA Equivalence
 Deterministic vs nondeterministic
 For every nondeterministic automata M1, there is
an equivalent deterministic automata M2

 Finite acceptors are equivalent iff they both accept


the same language

L(M1) = L(M2)
 Conversion Procedure is called the subset
construction

5
NFA (without ε) to DFA Conversion
 Simulate NFA moves with the DFA
 DFA start state:
• NFA start state
 Each DFA state:
• a subset of the set of NFA states
 New DFA states:
• Calculate the states reachable through each
tΣ
 Final DFA states:
• contain any NFA final state
NFA to DFA Conversion
 In DFA, label resultant state as a set of states
 [q1q2q3 ..]
 Number of states of the DFA can be
exponential in the number of states of the NFA
 For a set of |Q| states, there are exactly 2Q
subsets
 Finite number of states

7
Subset Construction
 Given an NFA MNFA = (Q, Σ, δ, q0, F), construct
equivalent DFA, MDFA = (Q′, Σ′, δ′ q0′, F′)
1. Q′ = 2Q (Set of subsets of Q)
2. q0′ = [q0]
3. F′ is the set of states of Q′ containing a
member of F
4. δ′([q1q2 .. qi], a) = [δ(q1, a) U δ(q2, a)U …
δ(qi, a)]
5. Σ′ = Σ

8
Example - 1
 Convert NFA to DFA for
M = ({q0, q1}, {0, 1}, q0, δ, {q1})

0 1
q0 0, 1 q1
q0 {q0, q1} {q1}
q1 ᵠ {q0, q1} 0 1 1

 Let MDFA = (Q′, Σ′, δ′ q0′, F′)

9
Step 1 - Q′
 The NFA has Q states
 The DFA has states from the power set
 For a set of |Q| states, there are exactly 2Q
subsets
 A state of Q′ is denoted by [q1q2…qi] where q1,
q2, … qi are states in Q
 [q1q2…qi] is a single state in M′ corresponding
to set of states of M
 Example: if Q = {q0, q1},
Q′ = {ᵠ, [q0], [q1], [q0q1]}
10
Step 2 - q0′

 Initial state of NFA: q0

 Initial state of DFA: [q0]

11
Step 3 - F′

 F′ is the set of states of Q′ containing a


member of F
 F = {q1}
 Q′ = {ᵠ, [q0], [q1], [q0q1]}

 F′= {[q1], [q0q1]}

12
Step 4 - δ′

 If a state makes transition to multiple states for


some input alphabet, then treat those multiple
states as a single state in the DFA
 δ′([q1q2…qi], a) = [δ(q1,a) U δ(q2,a) U … δ(qi,a)]
 δ′([q0], 0) = [δ(q0, 0)] = [q0q1]
 δ′([q0], 1) = [δ(q0,1)] = [q1]
 δ′([q1], 0) = [δ(q1, 0)] = ᵠ
 δ′([q1], 1) = [δ(q1,1)] = [q0q1]
 δ′([q0q1], 0) = [δ(q0, 0) U δ(q1, 0)] = [q0q1]
 δ′([q0q1], 1) = [δ(q0, 1) U δ(q1, 1)] = [q0q1] 13
Example – 1 Ans

δ′ 0 1
ᵠ ᵠ ᵠ
[q0] [q0q1] [q1]
*[q1] ᵠ [q0q1]
*[q0q1] [q0q1] [q0q1]

 Renaming [q0] to q0, [q1] to q1, [q0q1] to q2 and


ᵠ to q3
14
Example – 1 Ans
δ′ 0 1
q3 q3 q3
q0 q2 q1
*q1 q3 q2
*q2 q2 q2
1 0
q1
q3 0, 1
q0 1
0
q2 0, 1
15
Polling - 2
 For any DFA state [qiqj…qm] If some qj is a
final state in the NFA, then [qiqj…qm], is a final
state in the DFA
a) True
b) False

16
Example - 2
 Convert NFA to DFA

17
Example - 2
δ′ a b
ᵠ ᵠ ᵠ
[q0] [q0q1] [q0]
[q1] ᵠ [q2]
*[q2] ᵠ ᵠ
[q0q1] [q0q1] [q0q2]
*[q0q2] [q0q1] [q0]
*[q1q2] ᵠ [q2]
*[q0q1q2] [q0q1] [q0q2]
 States: [q1], [q2], [q1 q2], [q0q1q2] are not
reachable, can be eliminated 18
Example - 2
δ′ a b
[q0] [q0q1] [q0]
[q0q1] [q0q1] [q0q2]
*[q0q2] [q0q1] [q0]

19
Polling -3
 The construction time for DFA from an
equivalent NFA (m number of node)is:
a) O(m2)
b) O(2m)
c) O(m)
d) O(log m)

20
?
21

You might also like