Can Any NFA Be Converted to a DFA?
At a glance
- 1. Track state sets
Treat each DFA state as the set of NFA states that could be active after reading the same input.
- 2. Set the start state
Start with the NFA start state, or its epsilon-closure if epsilon transitions are allowed.
- 3. Compute transitions
For each input symbol, collect every state the NFA could reach from the current set.
- 4. Mark accepting sets
A DFA state is accepting if its set contains at least one accepting NFA state.
- 5. Keep reachable sets
Build only the subsets reachable from the start; there can be at most 2^n total subsets.
Yes. Every finite NFA has an equivalent DFA: one that accepts exactly the same strings. The standard method is called the subset construction (or powerset construction). It works by making a DFA state represent all the NFA states that might be active after reading an input prefix.
The conversion preserves the language, not the internal behavior of the machine. The NFA may have several possible paths for an input; the DFA records those possibilities together in a single state.
The subset construction
Let an NFA have state set , alphabet , start state , accepting states , and transition function . For each symbol, an NFA transition can lead to a set of states, so .
The DFA’s states are subsets of . Its start state is . From a subset and input symbol , the DFA moves to the union of all NFA states reachable on from states in :
A subset is accepting if it includes at least one accepting NFA state:
This rule captures the NFA’s acceptance condition: an input is accepted if at least one possible path ends in an accepting state. The DFA accepts when its tracked set contains such a state.
In principle, an NFA with states has subsets, including the empty set. In practice, you usually construct only subsets reachable from the start state. The empty subset, if reached, is a nonaccepting dead state: every input symbol takes it back to itself.
Worked example: recognizing a string containing ab
Consider an NFA over with states . Its start state is , and is accepting. The transitions are:
| NFA state | On a | On b |
|---|---|---|
The NFA can stay in while reading the input, and whenever it sees an a, it can also guess that this a begins the target substring. It then moves to if the next symbol is b. State loops on both symbols, so a match remains recognized. The NFA accepts exactly the strings containing ab.
Now name the reachable DFA subsets:
- , the start state;
- ;
- ;
- .
For example, from on a, the NFA transitions from to , so the DFA goes to . From on b, it collects the destinations from both states: leads to , and leads to . Thus the result is .
The complete reachable DFA is:
| DFA state | On a | On b | Accepting? |
|---|---|---|---|
| No | |||
| No | |||
| Yes | |||
| Yes |
The accepting DFA states are exactly the subsets containing . Although the NFA has three states and therefore eight possible subsets in total, only four subsets are reachable in this example.
What if the NFA has epsilon transitions?
An -NFA can change states without consuming an input symbol. In that case, use the epsilon-closure of a set: all states reachable from it using zero or more epsilon transitions.
Start the DFA in the epsilon-closure of the NFA’s start state. After taking transitions on a symbol, take the epsilon-closure of the resulting set as well. The accepting-state rule stays the same: a DFA subset is accepting if it contains an NFA accepting state. This adjustment still produces an equivalent DFA.
Common mistakes
- Taking just one NFA transition: If several destinations are possible, include all of them in the next subset.
- Marking a subset accepting only when all its states accept: The correct rule is “at least one.” NFA acceptance requires one successful path, not that every possible path succeeds.
- Forgetting the empty subset: If no NFA state can be reached on a symbol, the DFA needs a destination for that transition. The empty subset supplies it and loops to itself.
- Assuming the DFA must have the same number of states: The DFA can have more states—up to before unreachable states are removed. It may be minimized afterward without changing the language.
The subset construction applies to every standard finite NFA, including one with epsilon transitions. It establishes that NFAs and DFAs recognize the same class of languages: the regular languages.
References
- Introduction to the Theory of Computation — Michael Sipser
- Introduction to Automata Theory, Languages, and Computation — John E. Hopcroft, Rajeev Motwani, and Jeffrey D. Ullman
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.