...

/

Equivalence of NFAs and DFAs

Equivalence of NFAs and DFAs

Learn how to convert a nondeterministic finite automaton to a deterministic finite automaton.

Construct a DFA from a NFA

In this lesson, we will show how to convert a NFA to a DFA. Consider the language LL over {a,b}\{ a,b \}, which consists of strings that end and begin with the same symbol, i.e., L={all strings of length at least two that begin and end with the same symbol}.L = \{ \textrm{all strings of length at least two that begin and end with the same symbol} \}.

The NFA that accepts the language L is depicted in the figure below.

Press + to interact
NFA that accepts the language L
NFA that accepts the language L

The key idea is that for each state we have a (possibly empty) set of states to track for every input symbol. The tree in the figure below illustrates how things can progress as we begin with the start state of the original NFA, q0q_0, and track all possible moves while reading the first three symbols of any input string. In this case, going three levels deep suffices to observe all the possible states for this language. Multiple transitions leaving a state with the same symbol appear in horizontally adjacent boxes in the figure below.

Press + to interact
Tracking multiple out-edges simultaneously
Tracking multiple out-edges simultaneously

The symbol aa can reach either q1q_1 or q3q_3 from state q1q_1. We will combine these two states into a single, “composite” state, {q1,q3}\{q_1,q_3\}. The same logic applies to states q2q_2 and q3q_3 when leaving state q2q_2 with a bb, giving us the composite state {q2,q3}\{q_2,q_3\}. See the figure below.

Press + to interact
Combining like transitions into composite states
Combining like transitions into composite states

This tree suggests that five possible states suffice to process all possible movements: q0q_0, q1q_1, q2q_2, {q1,q3}\{q_1, q_3\}, and {q2,q3}\{q_2,q_3\}, giving the following equivalent DFA.

Press + to interact
DFA that accepts the language L
DFA that accepts the language L

Whenever a composite state contains any accepting state from the original NFA, that state becomes an accepting state in the resulting DFA. Thus, both states containing q3q_3 in the figure above are accepting states.

It is usually easier to track multiple moves in a NFA with a transition table instead of a tree. This is a transition table for the NFA.

State a\pmb{a} b\pmb{b}
q0\pmb{q_0} q1q_1 q2q_2
...
Access this course and 1400+ top-rated courses and projects.