Complete Guide: NFA↔DFA Conversion and DFA Minimization
Part 1: Converting NFA to DFA (Subset Construction Algorithm)
Step-by-Step Procedure:
Step 1: Understand the NFA
Identify states Q, alphabet Σ, transition function δ, initial state q₀, final states F
Note that δ(q, a) can return multiple states or empty set
Step 2: Handle ε-transitions (if present)
Compute ε-closure for each state
ε-closure(q) = {set of states reachable from q using only ε-transitions}
If no ε-transitions, ε-closure(q) = {q}
Step 3: Create DFA states
Each DFA state corresponds to a subset of NFA states
Initial DFA state = ε-closure({q₀})
Use power set construction
Step 4: Construct transition table
For each DFA state S and input symbol a:
1. Compute MOVE(S, a) = ∪{δ(q, a) | q ∈ S}
2. New DFA state = ε-closure(MOVE(S, a))
3. Add transition: δ'(S, a) = ε-closure(MOVE(S, a))
Step 5: Identify final states
DFA state is final if it contains at least one NFA final state
F' = {S ⊆ Q | S ∩ F ≠ ∅}
Step 6: Remove unreachable states
Keep only states reachable from initial state
Example: NFA to DFA Conversion
Given NFA:
States: {q₀, q₁, q₂}
Alphabet: {a, b}
Transitions:
δ(q₀, a) = {q₀, q₁}
δ(q₀, b) = {q₀}
δ(q₁, a) = ∅
δ(q₁, b) = {q₂}
δ(q₂, a) = {q₂}
δ(q₂, b) = {q₂}
Initial: q₀
Final: {q₂}
Step-by-step conversion:
Step 1: No ε-transitions, so ε-closure(q) = {q} for all states
Step 2: Create DFA states (subsets of NFA states):
A = {q₀} (initial state)
B = {q₀, q₁} (from δ(q₀, a))
C = {q₀, q₂} (from δ(q₀, b) and δ(q₁, b))
D = {q₀, q₁, q₂} (combination state)
Step 3: Construct transition table:
DFA State | Input 'a' | Input 'b' | Computation
----------|-----------|-----------|-------------
A = {q₀} | B = {q₀,q₁} | A = {q₀} | MOVE(A,a) = {q₀,q₁}, MOVE(A,b) = {q₀}
B = {q₀,q₁} | B = {q₀,q₁} | C = {q₀,q₂} | MOVE(B,a) = {q₀,q₁}, MOVE(B,b) = {q₀,q₂}
C = {q₀,q₂} | D = {q₀,q₁,q₂} | C = {q₀,q₂} | MOVE(C,a) = {q₀,q₁,q₂}, MOVE(C,b) = {q₀,q₂}
D = {q₀,q₁,q₂} | D = {q₀,q₁,q₂} | C = {q₀,q₂} | MOVE(D,a) = {q₀,q₁,q₂}, MOVE(D,b) = {q₀,q₂}
Step 4: Final states: C and D (contain q₂)
Final DFA:
States: {A, B, C, D}
Initial: A
Final: {C, D}
Transitions as computed above
Part 2: Converting DFA to NFA
Step-by-Step Procedure:
Step 1: Direct Conversion (Trivial)
Every DFA is already an NFA
Simply rewrite transition function format
Step 2: Formal Conversion
For DFA: δ(q, a) = p (single state)
For NFA: δ'(q, a) = {p} (set containing single state)
Step 3: Verification
Ensure no ε-transitions (DFA doesn't have them)
Each state-symbol pair maps to exactly one state
Example: DFA to NFA Conversion
Given DFA:
States: {q₀, q₁}
Alphabet: {0, 1}
Transitions:
δ(q₀, 0) = q₁
δ(q₀, 1) = q₀
δ(q₁, 0) = q₀
δ(q₁, 1) = q₁
Initial: q₀
Final: {q₁}
Equivalent NFA:
States: {q₀, q₁}
Alphabet: {0, 1}
Transitions:
δ'(q₀, 0) = {q₁}
δ'(q₀, 1) = {q₀}
δ'(q₁, 0) = {q₀}
δ'(q₁, 1) = {q₁}
Initial: q₀
Final: {q₁}
Part 3: DFA Minimization
Step-by-Step Procedure:
Step 1: Remove Unreachable States
Identify states reachable from initial state
Remove all unreachable states
Step 2: Identify Distinguishable States
Two states p and q are distinguishable if there exists a string w such that:
δ(p, w) ∈ F and δ(q, w) ∉ F, or
δ(p, w) ∉ F and δ(q, w) ∈ F
Step 3: Create Distinguishability Table
Create a table for all pairs of states
Mark pairs that are obviously distinguishable (one final, one non-final)
Step 4: Iterative Marking Algorithm
Repeat until no new pairs are marked:
For each unmarked pair (p, q) and each symbol a:
If δ(p, a) and δ(q, a) are distinguishable, mark (p, q)
Step 5: Partition States
States that are not distinguishable belong to the same equivalence class
Create partitions based on indistinguishable states
Step 6: Construct Minimized DFA
Each partition becomes a state in minimized DFA
Transitions between partitions
Initial state = partition containing original initial state
Final states = partitions containing original final states
Example: DFA Minimization
Given DFA:
States: {q₀, q₁, q₂, q₃, q₄}
Alphabet: {0, 1}
Transitions:
δ(q₀, 0) = q₁, δ(q₀, 1) = q₂
δ(q₁, 0) = q₃, δ(q₁, 1) = q₄
δ(q₂, 0) = q₄, δ(q₂, 1) = q₃
δ(q₃, 0) = q₃, δ(q₃, 1) = q₃
δ(q₄, 0) = q₄, δ(q₄, 1) = q₄
Initial: q₀
Final: {q₃, q₄}
Step-by-step minimization:
Step 1: All states are reachable from q₀
Step 2: Create distinguishability table:
Pairs: (q₀,q₁), (q₀,q₂), (q₀,q₃), (q₀,q₄), (q₁,q₂), (q₁,q₃), (q₁,q₄), (q₂,q₃), (q₂,q₄), (q₃,q₄)
Step 3: Mark obviously distinguishable pairs:
(q₀,q₃) ✓ (q₀ non-final, q₃ final)
(q₀,q₄) ✓ (q₀ non-final, q₄ final)
(q₁,q₃) ✓ (q₁ non-final, q₃ final)
(q₁,q₄) ✓ (q₁ non-final, q₄ final)
(q₂,q₃) ✓ (q₂ non-final, q₃ final)
(q₂,q₄) ✓ (q₂ non-final, q₄ final)
Step 4: Iterative marking:
Round 1:
(q₀,q₁): δ(q₀,0)=q₁, δ(q₁,0)=q₃ → (q₁,q₃) marked ✓
(q₀,q₂): δ(q₀,0)=q₁, δ(q₂,0)=q₄ → (q₁,q₄) marked ✓
(q₁,q₂): δ(q₁,0)=q₃, δ(q₂,0)=q₄ → check (q₃,q₄)
(q₃,q₄): δ(q₃,0)=q₃, δ(q₄,0)=q₄ → both final, need more analysis
Round 2:
(q₃,q₄): Both states go to themselves on all inputs → NOT distinguishable
Step 5: Equivalence classes:
[q₀] = {q₀}
[q₁] = {q₁}
[q₂] = {q₂}
[q₃] = {q₃, q₄} (equivalent states)
Step 6: Minimized DFA:
States: {[q₀], [q₁], [q₂], [q₃]}
Transitions:
δ([q₀], 0) = [q₁], δ([q₀], 1) = [q₂]
δ([q₁], 0) = [q₃], δ([q₁], 1) = [q₃]
δ([q₂], 0) = [q₃], δ([q₂], 1) = [q₃]
δ([q₃], 0) = [q₃], δ([q₃], 1) = [q₃]
Initial: [q₀]
Final: {[q₃]}
Alternative Method: Table-Filling Algorithm for DFA Minimization
Step-by-Step Procedure:
Step 1: Create Table
Create a triangular table for all pairs of states
Mark pairs where one is final and other is non-final
Step 2: Iterative Filling
For each unmarked pair (qi, qj):
For each input symbol a:
If δ(qi, a) and δ(qj, a) are marked as distinguishable:
Mark (qi, qj) as distinguishable
Step 3: Repeat Until No Changes
Continue until no new pairs are marked in an iteration
Step 4: Merge Equivalent States
Unmarked pairs are equivalent
Merge them into single states
Example Table-Filling:
Initial Table:
q₀ q₁ q₂ q₃
q₁ -
q₂ - -
q₃ ✓ ✓ ✓ -
q₄ ✓ ✓ ✓ ?
After iterations:
q₀ q₁ q₂ q₃
q₁ ✓
q₂ ✓ ✓
q₃ ✓ ✓ ✓ -
q₄ ✓ ✓ ✓ - (q₃ and q₄ are equivalent)
Summary of Key Algorithms
1. NFA to DFA (Subset Construction)
Time Complexity: O(2ⁿ × |Σ|) where n = number of NFA states
Space Complexity: O(2ⁿ)
Key Insight: Each DFA state represents a subset of NFA states
2. DFA to NFA (Trivial)
Time Complexity: O(1)
Space Complexity: O(1)
Key Insight: Every DFA is already an NFA
3. DFA Minimization
Time Complexity: O(n² × |Σ|) where n = number of DFA states
Space Complexity: O(n²)
Key Insight: Merge indistinguishable states
Common Mistakes to Avoid:
1. NFA to DFA: Forgetting to handle ε-closures properly
2. DFA Minimization: Not checking all symbol transitions when marking pairs
3. General: Confusing reachability with distinguishability
These algorithms are fundamental in automata theory and are frequently used in compiler design, lexical
analysis, and formal language processing.