Documente Academic
Documente Profesional
Documente Cultură
Peter Cappello
Department of Computer Science
University of California, Santa Barbara
Santa Barbara, CA 93106
cappello@cs.ucsb.edu
1
2.3 Equivalence of DFAs & NFAs
Clearly, for every DFA there is an equivalent NFA since every DFA
essentially is an NFA (be careful about the technicalities here).
It turns out that for every NFA there is an equivalent DFA. The proof
of this is constructive: Given an NFA, we construct an equivalent DFA.
The principle idea is that the DFA may have exponentially more states
than the NFA: If the NFA has |Q| states, the constructed DFA has at
2
most |2Q| states.
Consider the NFA in Fig. 3.
Figure 3: An NFA.
3
∗ ∗ ∗
(b) Compute v = δN (s1, a) ∪ δN (s2, a) ∪ . . . ∪ δN (sk , a).
(c) Add node v to QD , if it does not already exist.
(d) Add an arc labelled a from node u to node v.
3. Every state in GD whose label contains a q ∈ FN is in FD .
4. If MN accepts λ, the initial state of MD ({q0 }) is in FD .
This procedure terminates, since:
• Every iteration eliminates 1 missing arc from MD .
• MD has at most 2QN × |Σ| arcs.
We claim that the DFA is equivalent to the NFA:
w ∈ L(MN ) ⇔ w ∈ L(MD ).
It suffices to show that there is a path in MN labelled w from q0 to qi
if and only if there is a path in MD labelled w from {q0 } to some state
{. . . , qi, . . .}.
4
The proof is by induction on the length of the input string.
We show:
If there is a path in MN labelled w from q0 to qi then there is a path
in MD labelled w from {q0 } to some state {. . . , qi, . . .}.
The converse is left as an exercise.
5
Basis |w| = 1:
∗
If δN (q0, w) contains qi, then, by construction of MD , δ({q0}, w) maps
∗
to the state whose label is δN (q0 , w).
Induction hypothesis:
• Let |w| + n.
• If there is a path in MN labelled w from q0 to qi then there is a path
in MD labelled w from {q0 } to some state {. . . , qi, . . .}.
6
Induction step:
• Let |w| + n + 1.
• Assume: there is a path in MN labelled w from q0 to qi.
• Show: there is a path in MD labelled w from {q0 } to some state
{. . . , qi, . . .}.
7
4. Since δN (qj , a) contains qi, by construction of MD , there is an arc
labelled a from all states whose label contains qj to a state whose
label contains qi.
5. Thus, there is a path from MD ’s start state to a state whose label
contains qi ♦