Skip to article frontmatterSkip to article content

4.3Nondeterministic Finite Automata

The University of Melbourne

The finite automata we have seen so far are deterministic finite automata (DFA): given the current state and the next input symbol, there is exactly one state that a finite automaton can move to. In this section, we introduce nondeterministic finite automata (NFA), which have two additional features:

  1. An NFA’s state transition function takes as input the current state and the next input symbol, and is allowed to return, not just one state, but a subset of states.

  2. An NFA is also allowed to make transitions without consuming the next input symbol. These are called εε-transitions as it is as if the next input symbol is the empty string.

We will introduce these two features one by one.

4.3.1Transition to more than one state

Let NN be an NFA without εε-transitions. Consider a string w=v1v2vnw = v_1 v_2 \cdots v_n where each viv_i is an input symbol from Σ\Sigma. The NFA processes ww as follows. We use SiS_i to denote the set of states the NFA is in after processing v1viv_1\cdots v_i.

  1. Start at the start state: S0={q0}S_0 = \{q_0\}.

  2. For each input symbol viv_i (starting from v1v_1): define SiS_i to consist of states rr such that there exists qSi1q \in S_{i-1} and r=δ(q,vi)r = \delta(q,v_i).

  3. After all input symbols have been processed, it accepts the string if SnS_n contains an accepting state, and rejects it otherwise.

We can also view the NFA as having several possible state transition sequences of the form

q0v1r1v2r2v3vnrnq_0 \xrightarrow{v_1} r_1 \xrightarrow{v_2} r_2 \xrightarrow{v_3} \ldots \xrightarrow{v_n} r_n

where riδ(ri1,vi)r_i \in \delta(r_{i-1}, v_i) for each ii ranging from 1 to nn. Note that since δ(ri1,vi)\delta(r_{i-1},v_i) can be a set of more than one state, there can be several possible state transition sequences, and so there may be several resulting states. We denote by Q(w)Q(w) the set of resulting states.

The high level interpretation is as follows: Suppose the NFA NN is at state qq, the next input symbol is 0, and δ(q,0)=S\delta(q,0) = S for some set of states SS. Then, NN simultaneously transitions to all of them, in parallel. Each of these parallel “threads” then process the input independently of each other. Metaphorically, the universe is “split” into kk parallel universes, where kk is the size of SS. The NFA accepts the string iff it ends up in an accepting state in one of the universes.

Computation tree

Similar to DFAs, we can define a computation path to be a sequence of state transitions followed by NN while processing ww. We say that the path is accepting path if it ends in an accepting state and rejecting otherwise. Thus, an NFA accepts a string ww iff there exists an accepting computation path.

Observe that with DFAs, we have a single computation path for each input string. NFAs on the other hand, can have multiple computation paths. Consider the following NFA.

On input 110, it has 3 possible state transition sequences, each corresponding to a computation path.

q01q11q30q3q_0 \xrightarrow{1} q_1 \xrightarrow{1} q_3 \xrightarrow{0} q_3
q01q01q10q2q_0 \xrightarrow{1} q_0 \xrightarrow{1} q_1 \xrightarrow{0} q_2
q01q01q00q3q_0 \xrightarrow{1} q_0 \xrightarrow{1} q_0 \xrightarrow{0} q_3

We can in turn represent these paths using a tree, which we call a computation tree.

In this example, the string 110 is accepted by the NFA as there is one computation path (the one in the middle) ending in an accepting state.

4.3.2epsilon-transitions

An NFA with εε-transitions is one where instead of consuming the next input symbol and processing it using the transition function, the NFA can instead choose to follow an εε-transition which is a transition that does not consume the next input symbol.

Thus, in the state transition diagram, there may be edges that are labeled with ϵ\epsilon instead of a symbol from Σ\Sigma. Suppose the NFA NN is at state qq, the next input symbol is 0, and δ(q,ϵ)=S\delta(q,\epsilon) = S for some set of states SS. Then, NN can immediately transition simultaneously to the states in SS.

Let NN be an NFA. Consider a string w=v1v2vnw = v_1 v_2 \cdots v_n where each viΣ{ϵ}v_i \in \Sigma \cup \{\epsilon\}. A state qq is a resulting state of NN after processing ww iff there exists a sequence of state transitions:

r0v1r1v2r2v3vnrnr_0 \xrightarrow{v_1} r_1 \xrightarrow{v_2} r_2 \xrightarrow{v_3} \ldots \xrightarrow{v_n} r_n

where r0=q0r_0 = q_0, and riδ(ri1,vi)r_i \in \delta(r_{i-1}, v_i). Note that there may be several resulting states. We denote by Q(w)Q(w) the set of resulting states.

The definition of acceptance is the same as for NFAs without εε-transitions (Definition 2).

Computation tree

Consider the following NFA.

On input 10, it has 3 possible state transition sequences, each again corresponding to a computation path.

q0ϵq11q30q3q_0 \xrightarrow{\epsilon} q_1 \xrightarrow{1} q_3 \xrightarrow{0} q_3
q01q0ϵq10q2q_0 \xrightarrow{1} q_0 \xrightarrow{\epsilon} q_1 \xrightarrow{0} q_2
q01q00q3q_0 \xrightarrow{1} q_0 \xrightarrow{0} q_3

Here is its computation tree. Observe that for every root-to-leaf path, concatenating the symbols on the path gives us 10.

In this example, the string 10 is accepted by the NFA as there is one computation path (the one in the middle) ending in an accepting state.

Footnotes
  1. See Set notation for details on the notation 2Q2^Q.