DFA p1+Exercise-ToC Papadimiriou
DFA p1+Exercise-ToC Papadimiriou
DFA p1+Exercise-ToC Papadimiriou
55
56 Chapter 2: FINITE AUTOMATA
Input
tape
Finite
control
Figure 2-1
current state and the symbol just read -this is why we shall call this device a
deterministic finite automaton, to be contrasted to the nondeterministic version
introduced in the next section. After reading an input symbol, the reading head
moves one square to the right on the input tape so that on the next move it will
read the symbol in the next tape square. This process is repeated again and
again; a symbol is read, the reading head moves to the right, and the state of
the finite control changes. Eventually the reading head reaches the end of the
input string. The automaton then indicates its approval or disapproval of what
it has read by the state it is in at the end: if it winds up in one of a set of final
states the input string is considered to be accepted. The language accepted
by the machine is the set of strings it accepts.
When this informal account is boiled down to its mathematical essentials,
the following formal definition results.
The rules according to which the automaton M picks its next state are
encoded into the transition function. Thus if M is in state q E K and the
symbol read from the input tape is a E ~, then J(q, a) E K is the uniquely
determined state to which K passes.
Having formalized the basic structure of a deterministic finite automaton,
we must next render into mathematical terms the notion of a computation by
an automaton on an input string. This will be, roughly speaking, a sequence
of configurations that represent the status of the machine (the finite control,
reading head, and input tape) at successive moments. But since a deterministic
finite automaton is not allowed to move its reading head back into the part of
the input string that has already been read, the portion of the string to the left
of the reading head cannot influence the future operation of the machine. Thus
a configuration is determined by the current state and the unread part of the
string being processed. In other words, a configuration of a deterministic
finite automaton (K,~, J, s, F) is any element of K x ~*. For example, the
configur ation illustrated in Figure 2-1 is (q2, ababab).
The binary relation I- M holds between two configurations of 111 if and only
if the machine can pass from one to the other as a result of a single move. Thus
if (q,w) and (q',w') are two configurations of M, then (q,w) I-M (q',w') if and
only if w = aw' for some symbol a E ~, and J(q, a) = q'. In this case we say
58 Chapter 2: FINITE AUTOMATA
that (q,w) yields (q',w') in one step. Note that in fact I-M is a function from
K x ~+ to K x ~*, that is, for every configuration except those of the form (q, e)
there is a uniquely determined next configuration. A configuration of the form
(q, e) signifies that M has consumed all its input, and hence its operation ceases
at this point.
We denote the reflexive, transitive closure of I-M by I-~; (q,w) I-~ (q',w')
is read, (q,w) yields (q',w') (after some number, possibly zero, of steps). A
string w E ~* is said to be accepted by M if and only if there is a state q E F
such that (s, w) I-~ (q, e). Finally, the language accepted by M, L(M), is
the set of all strings accepted by M.
Example 2.1.1: Let M be the deterministic finite automaton (K,~, J, s, F),
where
K={qo,qd,
~ = {a,b},
s = qo,
F = {qo},
and J is the function tabulated below.
q (J J(q, (J)
qo a qo
qo b ql
ql a ql
ql b qo
It is then easy to see that L( M) is the set of all strings in {a, b} * that have
an even number of b's. For M passes from state qo to ql or from ql back to qo
when a b is read, but 111 essentially ignores a's, always remaining in its current
state when an a is read. Thus M counts b's modulo 2, and since qo (the initial
state) is also the sole final state, M accepts a string if and only if the number
of b's is even.
If M is given the input aabba, its initial configuration is (qo, aabba). Then
Therefore (qo, aabba) I-j,{ (qo, e), and so aabba is accepted by M. <:;
2.1: Deterministic Finite Automata 59
Figure 2-2
K = {qo, ql , q2, q3 } ,
"L,={a,b},
s = qo,
F = {qO,ql,q2},
q (J J(q, (J)
qo a qo
qo b ql
ql a qo
ql b q2
q2 a qo
q2 b q3
q3 a q3
q3 b q3
The state diagram is shown in Figure 2-3. To see that M does indeed accept
the specified language, note that as long as three consecutive b's have not been
read, M is in state qi (where i is 0, 1, or 2) immediately after reading a run of
i consecutive b's that either began the input string or was preceded by an a. In
particular, whenever an a is read and M is in state qo, ql, or q2, M returns to
60 Chapter 2: FINITE AUTOMATA
its initial state qo. States qo, ql, and q2 are all final, so any input string not
containing three consecutive b's will be accepted. However, a run of three b's
will drive AI to state q3, which is not final, and AI will then remain in this state
regardless of the symbols in the rest of the input string. State q3 is said to be
a dead state, and if AI reaches state q3 it is said to be tmpped, since no further
input can enable it to escape from this state.O
Figure 2-3
(1....--------~O
b
a,b
a,b
a, b a,b
a a b a
a,b a,b
b
b
b
a
62 Chapter 2: FINITE AUTOMATA
bib
I
1Faa~
bib ale
alw, which means "if the input symbol is a, follow this arrow and emit out-
put w". For example, the deterministic finite-state transducer over {a, b}
shown above transmits all b's in the input string but omits every other a.
(a) Draw state diagrams for deterministic finite-state transducers over {a, b}
that do the following.
(i) On input w, produce output an, where n is the number of occurrences
of the substring ab in w.
(ii) On input w, produce output an, where n is the number of occurrences
of the substring aba in w.
(iii) On input w, produce a string of length w whose ith symbol is an a if
i = 1, or if i > 1 and the ith and (i - l)st symbols of ware different;
otherwise, the ith symbol of the output is a b. For example, on input
aabba the transducer should output ababa, and on input aaaab it should
output abbba.
......-..---------i r-----------------------..
,, ,,
! a,b! a,b
~~
i ! a,b
,,, ,,
,L _.. _.. _____________ .. __ .. ___ _
___ .. __________ !
(a) Draw state diagrams for deterministic 2-tape finite automata that accept
each of the following.
(i) All pairs of strings (WI,W2) in {a,b}* x {a,b}* such that IWII = IW21,
and wI(i) i- w2(i) for all i.
(ii) All pairs of strings (WI, W2) in {a, b}' x {a, b} * such that the length of
W2 is twice the number of a's in Wi plus three times the number of b's
in Wi.
(iii) {(anb,anb m ) : n,m;:::: O}.
(iv) {(anb, amb n ) : n, m ;:::: O}.
2.1.6. This problem refers to Problems 2.1.5 and 2.1.6. Show that if f : ~* f-t ~* is
a function that can be computed by a deterministic finite-state transducer,
then {(w, f (w)) : W E ~*} is a set of pairs of strings accepted by some
deterministic two-tape finite automaton.
2.1. 7. We say that state q of a deterministic finite automaton M = (K, ~,J, qo, F)
is reachable if there exists W E ~* such that (qo, w) f-M (q, e). Show that
if we delete from NI any nonreachable state, an automaton results that
accepts the same language. Give an efficient algorithm for computing the
set of all reachable states of a deterministic finite automaton.