Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Informatique Théorique Spring 2011

Handout 3: Nondeterministic Finite Automata

3.1 Nondeterminism for finite automata. A nondeterministic finite automaton M = (Q, Σ, δ, q0 , F )


has the same components as a deterministic finite automaton, except that δ: Q×Σ → P(Q). Equivalently,
δ ⊆ Q×Σ×Q; that is, nondeterministic automata have transition relations instead of transition functions.
While according to a transition function, every state has precisely one successor on each input symbol,
according to a transition relation, a state may have zero, one, or more successors on an input symbol. If
there are zero successors, then it results in no run; if there are several successors, then it may result in
several runs. The automaton can be thought of as pursuing all possibilities in parallel (say, by replicating
itself), and accepting if at least one of the parallel copies of the automaton accepts. Equivalently, a
nondeterministic automaton can be thought of as magically guessing a sequence of choices that will lead
to an accept state if such a sequence exists.
A run of M is a sequence
a a an−1
s0 →0 s1 →1 ··· → sn
with s0 , . . . , sn ∈ Q and a0 , . . . , an−1 ∈ Σ such that

(1) s0 = q0 ,
(2) si+1 ∈ δ(si , ai ) for all i ∈ [0..n − 1].
The run accepts the input word a0 . . . an−1 if
(3) sn ∈ F .

The language of M is
L(M ) = {w ∈ Σ∗ | w is accepted by some run of M }.
In a deterministic automaton, each input word corresponds to precisely one run. In a nondeterministic
automaton, each input word may correspond to zero, one, or more runs.

3.2 Example. Check if second to last letter of the input is 1. Nondeterministic finite automaton N2 :

0,1


/ A 1 / B 0,1
/ C

In a deterministic automaton, we need to remember the 2 most recent input symbols. Deterministic
finite automaton D2 such that L(D2 ) = L(N2 ):


/ 00 1 / 01
O :
1
0 1
0
z 
10 o 11
0
W
1

1
c T.A. Henzinger, G. Théoduloz
3.3 Example. Check if third to last letter of the input is 1. Nondeterministic finite automaton N3 :

0,1


/ A 1 / B 0,1
/ C 0,1
/ D

In a deterministic automaton, we need to remember the 3 most recent input symbols. Deterministic
finite automaton D3 such that L(D3 ) = L(N3 ):

0 1

 
/ 000
1 / 001
1 / 011
1 / 111
O ? O
1 0
0 0 1 0

  
+
1
o 0
k o 1
100
h 010 101 110
0

3.4 Nondeterminism is exponentially more succinct than determinism. Check if k-th letter
from the end of the input is 1. A nondeterministic finite automaton (NFA) can check this with k + 1
states; a deterministic finite automaton (DFA) must remember the k most recent input symbols, which
requires 2k states.

3.5 Nondeterminism is no more expressive than determinism. While nondeterminism adds


succinctness, it does not add expressiveness: for every NFA N there is an DFA D such that L(D) = L(N ).
Consider the NFA N = (Q, Σ, δ, q0 , F ). We construct an equivalent DFA D = (Qd , Σ, δd , q0,d , Fd ) by
recording the set of possible NFA states for each prefix of the input:
Qd = P(Q),
δd (R, a) = {q ∈ Q | there exists r ∈ R such that q ∈ δ(r, a)}
(or equivalently, q ∈ δd (R, a) iff q ∈ δ(p, a) for some p ∈ R),
q0,d = {q0 },
Fd = {R ⊆ Q | R ∩ F 6= ∅}
(or equivalently, R ∈ Fd iff R ∩ F 6= ∅).
Each state of D is a set of states from N . This is called the subset construction. If N has n states, then
D has 2n states. Some of these states may be unreachable from the initial state, in which case they can
be omitted. Still, as we saw in Section 3.4, in general the exponential cost of determinization cannot be
avoided. If we apply the subset construction to the NFA N2 from Example 3.2, we obtain the following
DFA, which is identical to D2 :


/ A
1 / A,B
O :
1
0 1
0
z 
A,C o A,B,C
0
W
1

2
c T.A. Henzinger, G. Théoduloz
3.6 Epsilon-transitions. It is often convenient to permit an automaton transition without reading
an input symbol. Such transitions are called ε-transitions, where ε is the empty word. They often give
rise to nondeterministic choice. A finite automaton M ε = (Q, Σ, δ ε , q0 , F ε ) with ε-transitions —that
is, δ ε : Q × (Σ ∪ {ε}) → P(Q)— can be converted into an equivalent NFA M = (Q, Σ, δ, q0 , F ) without
ε-transitions in linear time:
ε ε a
q ∈ δ(p, a) iff M ε has a run of the form p = s0 → · · · →sn →q,
ε ε
p ∈ F iff M ε has a run of the form p = s0 → · · · →sn for some sn ∈ F ε .

3.7 Intersection and union of nondeterministic automata. The intersection and union of NFAs
can be constructed as for DFAs, using the product construction. But there is also a simpler way for
building the union. If M1 = (Q1 , Σ, δ1 , q01 , F1 ) and M2 = (Q2 , Σ, δ2 , q02 , F2 ), then the union can be
defined as follows:
M∪ε = (Q1 ∪ Q2 ∪ {qnew }, Σ, δ1 ∪ δ2 ∪ {(qnew , ε, q01 ), (qnew , ε, q02 )}, qnew , F1 ∪ F2 )

M∪ε
M1
9

/ qnew

ε
M2
%

where qnew 6∈ (Q1 ∪ Q2 ). Note that this construction requires |Q1 | + |Q2 | + 1 instead of |Q1 | · |Q2 | states.
If desired, the two ε-transitions can be removed as in Section 3.5.

3.8 Complementation of deterministic and nondeterministic automata. The complement of a


language L over the alphabet Σ is L = Σ∗ \L. Consider the two finite automata M = (Q, Σ, δ, q0 , F )
and M = (Q, Σ, δ, q0 , Q\F ). These two automata have the same runs, but an accepting run of M is a
rejecting run of M , and vice versa. If M is deterministic, there is a one-to-one correspondence between
input words and runs, and therefore L(M ) = L(M ). However, if M is nondeterministic, there is a one-
to-many correspondence between input words and runs, and complementing the acceptance condition
for runs does not complement the language. For example, both automata

0,1 0,1

 
/ A 1 / B / A 1 / B

0 1 0 1
accept the input word 01, because it corresponds to two runs, a→a→b and a→a→a, one accepting and
the other rejecting (in either automaton). In fact, there is no simpler way for complementing an NFA
other than first determinizing it (using the subset construction), and then swapping final and nonfinal
states. This, of course, has exponential cost.

3
c T.A. Henzinger, G. Théoduloz
3.9 Summary of boolean operations.
DFAs NFAs
Intersection of n1 -state automaton with n2 -state automaton n1 · n2 states1 n1 · n2 states1
Union of n1 -state automaton with n2 -state automaton n1 · n2 states1 n1 + n2 + 1 states
Complement of n-state automaton n states 2n states2
1
product construction
2
subset construction

4
c T.A. Henzinger, G. Théoduloz

You might also like