We have observed nondeterminism in two slightly different forms in our discussion of NFAs. It is most apparent if there is a state and an alphabet symbol such that several different transitions are possible in state on input . A choice of moves can also occur as a result of -transitions, because there may be states from which the NFA can make either a transition on an input symbol or one on no input.
We will see in this section that both types of nondeterminism can be eliminated. The idea in the second case is to introduce new transitions so that we no longer need -transitions: In every case where there is no -transition from to but the NFA can go from to by using one or more ’s as well as , we will introduce the -transition. The resulting NFA may have even more nondeterminism of the first type than before, but it will be able to accept the same strings without using -transitions.
The way we eliminate nondeterminism from an NFA having no -transitions is simply to define it away, by finding an appropriate definition of state. We have used this technique twice before, in Section 2.2 when we considered states that were ordered pairs, and in Section 2.5 when we defined a state to be a set of strings. Here a similar approach is already suggested by the way we define the transition function of an NFA, whose value is a set of states. If we say that for an element of a set , the transition on input can possibly go to several states, it sounds like nondeterminism; if we say that starting with an element of the set , the set of states to which we can go on input is
and if both and this set qualify as states in our new definition, then it sounds as though we have eliminated the nondeterminism. The only question then is whether the FA we obtain accepts the same strings as the NFA we started with.
Theorem 3.17
For every language accepted by an NFA , there is an NFA with no -transitions that also accepts .
ProofTheorem 3.17
As we have already mentioned, we may need to add transitions in order to guarantee that the same strings will be accepted even when the -transitions are eliminated. In addition, if but , we will also make an accepting state of in order to guarantee that accepts . We define
where for every , , and for every and every ,
Finally, we define
For every state and every , the way we have defined the extended transition function for the NFA tells us that is the set of states can reach by using the symbols of together with -transitions. The point of our definition of is that we want to be the same set, even though has no -transitions. This may not be true for , because and ; this is the reason for the definition of above. We sketch the proof that for every and every with ,
Transcription note
In the preceding paragraph, the printed uses the extended transition function: . The ordinary transition value was defined to be .
The proof is by structural induction on . If , then by definition of , , and because has no -transitions, (see Exercise 3.24).
Suppose that for some with , for every state , and let be an arbitrary element of .
The last step in the induction proof is to check that this last expression is indeed . This is a special case of the general formula
See Exercise 3.30 for the details.
Now we can verify that . If the string is accepted by , then it is accepted by , because in this case by definition. If , then ; therefore, , and .
Suppose that . If , then contains an element of ; therefore, since and , .
Now suppose and . Then contains an element of . The state is in only if ; therefore, if (which is the same as ) contains , it also contains every element of in . In any case, if , then must contain an element of , which implies that .
Theorem 3.18
For every language accepted by an NFA , there is an FA that also accepts .
ProofTheorem 3.18
Because of Theorem 3.17, it is sufficient to prove the theorem in the case when has no -transitions. The formulas defining are simplified accordingly: and .
The finite automaton can be defined as follows, using the subset construction: The states of are sets of states of , or
The initial state of is . For every and every ,
and the accepting states of are defined by the formula
The last definition is the correct one, because a string should be accepted by if, when the NFA processes , there is at least one state it might end up in that is an element of .
There is no doubt that is an ordinary finite automaton. The expression , however, is a set of states of —not because is nondeterministic, but because we have defined states of to be sets of states of . The fact that the two devices accept the same language follows from the fact that for every ,
and we now prove this formula using structural induction on . We must keep in mind during the proof that and are defined in different ways, because is an FA and is an NFA.
If , then
The induction hypothesis is that is a string for which , and we must show that for every , .
A string is accepted by precisely if . We know now that this is true if and only if ; and according to the definition of , this is true if and only if . Therefore, is accepted by if and only if is accepted by .
We present three examples: one that illustrates the construction in Theorem 3.17, one that illustrates the subset construction in Theorem 3.18, and one in which we use both to convert an NFA with -transitions to an ordinary FA.
Example 3.19Eliminating -Transitions from an NFA
Figure 3.20a shows the transition diagram for an NFA with -transitions; it is not hard to see that it accepts the language corresponding to the regular expression . We show in tabular form the values of the transition function , as well as the values and that will give us the transition function in the resulting NFA .
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 |
For example, the value is the set , because and there are -transitions from 4 to 1 and from 1 to 2.
Figure 3.20b shows the NFA , whose transition function has the values in the last two columns of the table. In this example, the initial state of is already an accepting state, and so drawing the new transitions and eliminating the -transitions are the only steps required to obtain .
(a)
(b)
Eliminating -transitions from an NFA.
Example 3.21Using the Subset Construction to Eliminate Nondeterminism
We consider the NFA in Example 3.6, shown in Figure 3.7. Instead of labeling states as , here we will use only the subscript . We will describe the FA obtained from the construction in the proof of Theorem 3.18. Because a set with elements has subsets, using this construction might require an exponential increase in the number of states. As this example will illustrate, we can often get by with fewer by considering only the states of (subsets of ) that are reachable from , the initial state of .
It is helpful, and in fact recommended, to use a transition table for in order to obtain the values of . The table is shown below.
| 0 | ||
| 1 | ||
| 2 | ||
| 3 | ||
| 4 |
The transition diagram for is shown in Figure 3.22. For example, . If you compare Figure 3.22 to Figure 2.23c, you will see that they are the same except for the way the states are labeled. The subset construction doesn’t always produce the FA with the fewest possible states, but in this example it does.
Applying the subset construction to the NFA in Example 3.21.
Example 3.23Converting an NFA with -Transitions to an FA
For the NFA pictured in Figure 3.24a, we show the transition function in tabular form below, as well as the transition function for the resulting NFA without -transitions. It is pictured in Figure 3.24b.
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 |
Converting an NFA to an FA.
The subset construction gives us a slightly greater variety of subsets this time, but still considerably fewer than the total number of subsets of . The final FA is shown in Figure 3.24c.