Professional Documents
Culture Documents
L6 NFA To DFA
L6 NFA To DFA
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
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
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
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′
11
Step 3 - F′
12
Step 4 - δ′
δ′ 0 1
ᵠ ᵠ ᵠ
[q0] [q0q1] [q1]
*[q1] ᵠ [q0q1]
*[q0q1] [q0q1] [q0q1]
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