Constructing a DFA from an NFA
5.1.4 Constructing a DFA from an NFA
Is it possible to express more languages by means of nondeterministic finite-state automata than by deterministic finite-state automata? For each nondeterministic automaton it is possible to give a deterministic finite-state automaton such that both automata accept the same language, so the answer to the above question is
Regular Languages
no. Before we give the formal proof of this claim, we illustrate the construction of a DFA for an NFA in an example.
Consider the nondeterministic finite-state automaton corresponding with the exam- ple grammar of the previous subsection.
c GF A ED
?>=< 89:; S oo
a ?>=< 89:; .-, ()+
A ?>=< 89:; B
The nondeterminicity of this automaton appears in state A: two outgoing arcs of A are labelled with an a. Suppose we add a new state D, with an arc from A to D labelled a, and we remove the arcs labelled a from A to S and from A to B. Since
D is a merge of the states S and B we have to merge the outgoing arcs from S and
B into outgoing arcs of D. We obtain the following automaton.
?>=< 89:; .-, ()+ C
A ?>=< 89:; D ?>=< 89:; B
OO A BC
b
We omit the proof that the language of the latter automaton is equal to the language of the former one. Although there is just one outgoing arc from A labelled with a, this automaton is still nondeterministic: there are two outgoing arcs labelled with
c from D. We apply the same procedure as above. Add a new state E and an arc labelled c from D to E, and remove the two outgoing arcs labelled c from D. Since
E is a merge of the states C and S we have to merge the outgoing arcs from C and S into outgoing arcs of E. We obtain the following automaton.
c GF A ED
?>=< 89:; S a
?>=< 89:; .-, ()+ C
A ?>=< 89:; D ?>=< 89:; ()+ .-, E 89:; ?>=< B
Again, we do not prove that the language of this automaton is equal to the language of the previous automaton, provided we add the state E to the set of accepting
5.1 Finite-state automata
states, which until now consisted just of state C. State E is added to the set of accepting states because it is the merge of a set of states among which at least one belongs to the set of accepting states. Note that in this automaton for each state, all outgoing arcs are labelled differently, i.e. this automaton is deterministic. The DFA constructed from the NFA above is the 5-tuple (X, Q, d, S, F ) with
X = {a, b, c} Q = {S, A, B, C, D, E}
F = {C, E} where transition function d is defined by
dEc = S This construction is called the ‘subset construction’. In general, the construction
works as follows. Suppose M = (X, Q, d, Q 0 , F ) is a nondeterministic finite-state au- tomaton. Then the finite-state automaton M 0 = (X 0 ,Q 0 ,d 0 ,Q 0 ,F 0 ), the components
of which are defined below, accepts the same language.
X 0 = X Q 0 = subs Q
where subs returns all subsets of a set. subs Q is also called the powerset of Q. For example,
subs :: {X} → {{X}} subs {A, B} = {{ }, {A}, {A, B}, {B}}
For the other components of M 0 we define
The proof of the following theorem is given in Section 5.4.
Regular Languages
Theorem 7: DFA for NFA
For every nondeterministic finite-state automaton M there exists a finite-state au-
tomaton M 0 such that Lnfa(M ) = Ldfa(M 0 )
Theorem 7 enables us to freely switch between NFA’s and DFA’s. Equipped with this knowledge we continue the exploration of regular languages in the following section. But first we show that the transformation from an NFA to a DFA is an instance of partial evaluation.