...

/

Nondeterministic Finite Automata

Nondeterministic Finite Automata

Learn about nondeterministic finite automata through several examples.

Introducing nondeterminism

Consider the language KK, which contains strings with a 11 in the third-to-last position. We can write it as K={all strings of 0’s and 1’s ending with 100,101,110, or 111}.K = \{ \textrm{all strings of } 0 \textrm{'s and } 1 \textrm{'s ending with } 100,\:101,\:110, \textrm{ or } 111 \}.

It will require a lot of effort to make a DFA that accepts the language KK. It is possible, however, to more succinctly express the idea of “ends with a 11 in the third-to-last position” than a DFA allows. With nondeterminism, we can get right to the point of expressing exactly what we want, as shown in the nondeterministic finite automaton (NFA) in the following figure.

Press + to interact
A NFA that accepts the language K
A NFA that accepts the language K

Two things stand out in the transition graph above. First, there are two choices for transitions from the initial state for an input of the symbol 11; we may either stay in state 00 or move to state 11. This is what makes this machine nondeterministic. Second, there are no out-edges exiting the accepting state. This is because we want to end there. For a string to end in the accepting state, we must choose the edge from state 00 to state 11 at just the right moment. If such a choice can be made, we say that the NFA accepts the string. An accepting path for the input string 1011010110 is the sequence of states 0,0,0,1,1?,1??0,0,0,1,1?,1??. Clearly, only strings with a 11 in the correct position can end in the final state. The important thing here is how much easier it is to conceive and express a NFA for this language than a DFA.

This may seem a strange approach to designing finite automata, and programming such a machine may appear to require some sort of backtracking procedure, in case we don’t make the right choice (because we don’t know ahead of time when an input symbol is the last one in the string). Alas, we can’t “back up” in a finite automaton; all decisions must be made based only on the current state and input symbol. Fortunately, it is possible to convert any NFA to a DFA by keeping track of all possible moves as we go. Let’s see some more NFAs.

NFA accepting strings that begin and end with the same symbol

The NFA in the figure below accepts a language LL over {a,b}\{a,b \}, which contains strings of length two or greater that begin and end with the same symbol. We can write it as 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} \}.

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

The nondeterminism occurs in the middle states, where there are two choices for aa and b ...