Cs · Computer Science

Can Any NFA Be Converted to a DFA?

Published By the 9to5Science editorial team

At a glance

  1. 1. Track state sets

    Treat each DFA state as the set of NFA states that could be active after reading the same input.

  2. 2. Set the start state

    Start with the NFA start state, or its epsilon-closure if epsilon transitions are allowed.

  3. 3. Compute transitions

    For each input symbol, collect every state the NFA could reach from the current set.

  4. 4. Mark accepting sets

    A DFA state is accepting if its set contains at least one accepting NFA state.

  5. 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 QQ, alphabet Σ\Sigma, start state q0q_0, accepting states FF, and transition function δ\delta. For each symbol, an NFA transition can lead to a set of states, so δ(q,a)⊆Q\delta(q,a) \subseteq Q.

The DFA’s states are subsets of QQ. Its start state is {q0}\{q_0\}. From a subset SS and input symbol aa, the DFA moves to the union of all NFA states reachable on aa from states in SS:

δD(S,a)=⋃q∈Sδ(q,a).\delta_D(S,a)=\bigcup_{q\in S}\delta(q,a).

A subset is accepting if it includes at least one accepting NFA state:

FD={S⊆Q:S∩F≠∅}.F_D=\{S\subseteq Q:S\cap F\ne\varnothing\}.

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 nn states has 2n2^n 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 {a,b}\{a,b\} with states q0,q1,q2q_0,q_1,q_2. Its start state is q0q_0, and q2q_2 is accepting. The transitions are:

NFA stateOn aOn b
q0q_0{q0,q1}\{q_0,q_1\}{q0}\{q_0\}
q1q_1∅\varnothing{q2}\{q_2\}
q2q_2{q2}\{q_2\}{q2}\{q_2\}

The NFA can stay in q0q_0 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 q2q_2 if the next symbol is b. State q2q_2 loops on both symbols, so a match remains recognized. The NFA accepts exactly the strings containing ab.

Now name the reachable DFA subsets:

  • A={q0}A=\{q_0\}, the start state;
  • B={q0,q1}B=\{q_0,q_1\};
  • C={q0,q2}C=\{q_0,q_2\};
  • D={q0,q1,q2}D=\{q_0,q_1,q_2\}.

For example, from AA on a, the NFA transitions from q0q_0 to {q0,q1}\{q_0,q_1\}, so the DFA goes to BB. From BB on b, it collects the destinations from both states: q0q_0 leads to q0q_0, and q1q_1 leads to q2q_2. Thus the result is {q0,q2}=C\{q_0,q_2\}=C.

The complete reachable DFA is:

DFA stateOn aOn bAccepting?
A={q0}A=\{q_0\}BBAANo
B={q0,q1}B=\{q_0,q_1\}BBCCNo
C={q0,q2}C=\{q_0,q_2\}DDCCYes
D={q0,q1,q2}D=\{q_0,q_1,q_2\}DDCCYes

The accepting DFA states are exactly the subsets containing q2q_2. 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 ε\varepsilon-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 2n2^n 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

  1. Introduction to the Theory of Computation — Michael Sipser
  2. 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.