Suppose we are given an NFA \(N = (P, \Sigma, p_0, \partial, F_p)\text{,}\) and we want to build a DFA \(D=(Q, \Sigma, q_0, \delta, F_q)\) that accepts the same language. The idea is to make the states in \(D\) correspond to subsets of \(N\)’s states, and then to set up \(D\)’s transition function \(\delta\) so that for any string \(w\text{,}\) \(\delta^*(q_0, w)\) corresponds to \(\partial^*(p_0,w)\text{;}\) i.e. the single state that \(w\) gets you to in \(D\) corresponds to the set of states that \(w\) could get you to in \(N\text{.}\) If any of those states is accepting in \(N\text{,}\) \(w\) would be accepted by \(N\text{,}\) and so the corresponding state in \(D\) would be made accepting as well.
So how do we make this work? The first thing to do is to deal with a start state \(q_0\) for \(D\text{.}\) If we’re going to make this state correspond to a subset of \(N\)’s states, what subset should it be? Well, remember (1) that in any DFA, \(\delta^*(q_0, \varep) = q_0\text{;}\) and (2) we want to make \(\delta^*(q_0,
w)\) correspond to \(\partial^*(p_0,w)\) for every \(w\text{.}\) Putting these two limitations together tells us that we should make \(q_0\) correspond to \(\partial^*(p_0,
\varep)\text{.}\) So \(q_0\) corresponds to the subset of all of \(N\)’s states that can be reached with no input.
Now we progressively set up \(D\)’s transition function \(\delta\) by repeatedly doing the following:
find a state \(q\) that has been added to \(D\) but whose out-transitions have not yet been added. (Note that \(q_0\) initially fits this description.) Remember that the state \(q\) corresponds to some subset \(\{p_1,
\ldots , p_n\}\) of \(N\)’s states.
for each input symbol \(a\text{,}\) look at all \(N\)’s states that can be reached from any one of \(p_1, \ldots , p_n\) by consuming \(a\) (perhaps making some \(\varep\)-transitions as well). That is, look at \(\partial^*(p_1,a)
\cup \ldots \cup
\partial^*(p_n,a)\text{.}\) If there is not already a DFA state \(q'\) that corresponds to this subset of \(N\)’s states, then add one, and add the transition \(\delta(q, a)= q'\) to \(D\)’s transitions.
The above process must halt eventually, as there are only a finite number of states \(n\) in the NFA, and therefore there can be at most \(2^n\) states in the DFA, as that is the number of subsets of the NFA’s states. The final states of the new DFA are those where at least one of the associated NFA states is an accepting state of the NFA.
Can we now argue that \(L(D) = L(N)\text{?}\) We can, if we can argue that \(\delta^*(q_0,w)\) corresponds to \(\partial^*(p_0,w)\) for all \(w
\in\Sigma^*\text{:}\) if this latter property holds, then \(w \in L(D)\) iff \(\delta^*(q_0,w)\) is accepting, which we made be so iff \(\partial^*(p_0,w)\) contains an accepting state of \(N\text{,}\) which happens iff \(N\) accepts \(w\) i.e. iff \(w \in L(N)\text{.}\)
So can we argue that \(\delta^*(q_0,w)\) does in fact correspond to \(\partial^*(p_0,w)\) for all \(w\text{?}\) We can, using induction on the length of \(w\text{.}\)
First, a preliminary observation. Suppose \(w=xa\text{,}\) i.e. \(w\) is the string \(x\) followed by the single symbol \(a\text{.}\) How are \(\partial^*(p_0,x)\) and \(\partial^*(p_0,w)\) related? Well, recall that \(\partial^*(p_0,x)\) is the set of all states that \(N\) can reach when it starts in \(p_0\) and consumes \(x\text{:}\) \(\partial^*(p_0,x) = \{p_1,
\ldots, p_n\}\) for some states \(p_1, \ldots, p_n\text{.}\) Now, \(w\) is just \(x\) with an additional \(a\text{,}\) so where might \(N\) end up if it starts in \(p_0\) and consumes \(w\text{?}\) We know that \(x\) gets \(N\) to \(p_1\) or \(\ldots\) or \(p_n\text{,}\) so \(xa\) gets \(N\) to any state that can be reached from \(p_1\) with an \(a\) (and maybe some \(\varep\)-transitions), and to any state that can be reached from \(p_2\) with an \(a\) (and maybe some \(\varep\)-transitions), etc. Thus, our relationship between \(\partial^*(p_0,x)\) and \(\partial^*(p_0,w)\) is that if \(\partial^*(p_0,x)
= \{p_1, \ldots, p_n\}\text{,}\) then \(\partial^*(p_0,w) = \partial^*(p_1,a)
\cup \ldots \cup \partial^*(p_n,a)\text{.}\) With this observation in hand, let’s proceed to our proof by induction.
We want to prove that \(\delta^*(q_0,w)\) corresponds to \(\partial^*(p_0,w)\) for all \(w \in\Sigma^*\text{.}\) We use induction on the length of \(w\text{.}\)
Base case: Suppose \(w\) has length 0. The only string \(w\) with length 0 is \(\varep\text{,}\) so we want to show that \(\delta^*(q_0,\varep)\) corresponds to \(\partial^*(p_0,\varep)\text{.}\) Well, \(\delta^*(q_0, \varep) =
q_0\text{,}\) since in a DFA, \(\delta^*(q, \varep) = q\) for any state \(q\text{.}\) We explicitly made \(q_0\) correspond to \(\partial^*(p_0,\varep)\text{,}\) and so the property holds for \(w\) with length 0.
-
Inductive case: Assume that the desired property holds for some number \(n\text{,}\) i.e. that \(\delta^*(q_0,x)\) corresponds to \(\partial^*(p_0,x)\) for all \(x\) with length \(n\text{.}\) Look at an arbitrary string \(w\) with length \(n+1\text{.}\) We want to show that \(\delta^*(q_0,w)\) corresponds to \(\partial^*(p_0,w)\text{.}\) Well, the string \(w\) must look like \(xa\) for some string \(x\) (whose length is \(n\)) and some symbol \(a\text{.}\) By our inductive hypothesis, we know \(\delta^*(q_0,x)\) corresponds to \(\partial^*(p_0,x)\text{.}\) We know \(\partial^*(p_0,x)\) is a set of \(N\)’s states, say \(\partial^*(p_0,x) =
\{p_1, \ldots, p_n\}\text{.}\)
At this point, our subsequent reasoning might be a bit clearer if we give explicit names to \(\delta^*(q_0,w)\) (the state \(D\) reaches on input \(w\)) and \(\delta^*(q_0,x)\) (the state \(D\) reaches on input \(x\)). Call \(\delta^*(q_0, w)\) \(q_w\text{,}\) and call \(\delta^*(q_0,x)\) \(q_x\text{.}\) We know, because \(w=xa\text{,}\) there must be an \(a\)-transition from \(q_x\) to \(q_w\text{.}\) Look at how we added transitions to \(\delta\text{:}\) the fact that there is an \(a\)-transition from \(q_x\) to \(q_w\) means that \(q_w\) corresponds to the set \(\partial^*(p_1,a)
\cup \ldots \cup \partial^*(p_n,a)\) of \(N\)’s states. By our preliminary observation, \(\partial^*(p_1,a) \cup \ldots \cup
\partial^*(p_n,a)\) is just \(\partial^*(p_0,w)\text{.}\) So \(q_w\) (or \(\delta^*(q_0,w)\)) corresponds to \(\partial^*(p_0,w)\text{,}\) which is what we wanted to prove. Since \(w\) was an arbitrary string of length \(n+1\text{,}\) we have shown that the property holds for \(n+1\text{.}\)
Altogether, we have shown by induction that \(\delta^*(q_0,w)\) corresponds to \(\partial^*(p_0,w)\) for all \(w \in\Sigma^*\text{.}\) As indicated at the very beginning of this proof, that is enough to prove that \(L(D)= L(N)\text{.}\) So for any NFA \(N\text{,}\) we can find a DFA \(D\) that accepts the same language.