Professional Documents
Culture Documents
Handout 3: Nondeterministic Finite Automata: C T.A. Henzinger, G. TH Eoduloz
Handout 3: Nondeterministic Finite Automata: C T.A. Henzinger, G. TH Eoduloz
(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.
/ 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.
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