Please note that there is more than one way to

HOMEWORK ONE SOLUTION– CSE 355
DUE: 08 FEBRUARY 2011
Please note that there is more than one way to answer most of
these questions. The following only represents a sample solution.
(1) (a) Construct a state diagram for a DFA M1 to recognize the language over Σ = {a, b}
defined by L1 = {w : the number of as in w is even}.
Answer:
b
b
a
q0
q1
a
(b) Construct a state diagram for a DFA M2 to recognize the language over Σ = {a, b}
defined by L2 = {w : the number of bs in w is at most 3}.
Answer:
a
a
b
q2
a
b
q3
a
b
q4
a,b
b
q5
q6
(c) Using the method in Theorem 1.25 and your answers to the (a) and (b) parts, construct
a state diagram for a DFA M3 to recognize the language over Σ = {a, b} defined by
L3 = {w : the number of as in w is even or the number of bs in w is at most 3}.
Answer:
b
(q0,q2)
a
(q1,q2)
a
a
b
b
(q0,q3)
(q1,q3)
a
a
b
1
b
(q0,q4)
(q1,q4)
a
a
b
b
(q0,q5)
(q1,q5)
a
a
b
b
(q0,q6)
(q1,q6)
a
b
(d) Using the method in the footnote on page 46 and your answers to the (a) and (b) parts,
construct a state diagram for a DFA M4 to recognize the language over Σ = {a, b} defined by L4 = {w : the number of as in w is even and the number of bs in w is at most 3}.
Answer:
b
(q0,q2)
a
a
(q1,q6)
b
(q0,q3)
a
b
a
a
(q1,q6)
b
(q0,q4)
b
a
(q1,q6)
b
(q0,q5)
a
b
a
(q1,q6)
b
(q1,q6)
a
b
a
(q1,q6)
b
(e) By whatever method you like, construct a state diagram for a DFA M5 to recognize
the language over Σ = {a, b} defined by L5 = {wz : the number of as in w is even and
the number of bs in z is at most 3}.
Answer:
Note that the language L5 is equivalent to {w : the number of as in w is even, or
the number of as in w is odd and there is at most 3 bs in w after the last a}.
b
a
q0
a
a
a
q1
b
q2
a
a
q3
b
2
b
q4
b
q5
b
(f) Consider the three languages L1 ∪ L2 , L1 ∩ L2 , and L1 L2 . For each pair of these, is
one of the languages contained in the other? Is either properly contained in the other?
Explain.
Solution:
L1 ∩ L2 is properly contained (and hence contained) in L1 ∪ L2 . To see containment
note that if w ∈ L1 ∩ L2 then w ∈ L1 so w ∈ L1 ∪ L2 . To see the containment is proper
note the string a is in L2 and is thus in L1 ∪ L2 , but a does not have any even number
of as and is thus not in L1 and so it cannot be in L1 ∩ L2 . Since L1 ∩ L2 is properly
contained in L1 ∪ L2 , L1 ∪ L2 is not contained in L1 ∩ L2 .
L1 ∪ L2 is properly contained in L1 L2 . To see containment note that if w ∈ L1 ∪ L2
then w ∈ L1 or w ∈ L2 . If w ∈ L1 , then w = w ∈ L1 L2 since ∈ L2 . Similarly, if
w ∈ L2 , then w = w ∈ L1 L2 since ∈ L1 . To see the containment is proper, note that
bbbab ∈ L1 L2 , since bbb ∈ L1 (has 0 as) and ab ∈ L2 (has 1 b), but bbbab does not have
an even number of as and is thus not in L1 and bbbab has more than three bs so it is
also not in L2 . Thus bbbab cannot be in L1 ∪ L2 . Since L1 ∪ L2 is properly contained
in L1 L2 , L1 L2 is not contained in L1 ∪ L2 .
L1 ∩ L2 is properly contained in L1 L2 . One way to see this is to realize that proper
containment is a transitive property, which means since L1 ∩ L2 is properly contained
in L1 ∪ L2 and L1 ∪ L2 is properly contained in L1 L2 , then L1 ∩ L2 must be properly
contained in L1 L2 .
Another way is to proceed as we did above. To see containment note that if w ∈ L1 ∩L2
then w ∈ L1 and w = w ∈ L1 L2 since ∈ L2 . To see the containment is proper, note
that a = a ∈ L1 L2 , but a does not have an even number of as and is thus not in L1
and so it cannot be in L1 ∩ L2 . Since L1 ∩ L2 is properly contained in L1 L2 , L1 L2 is
not contained in L1 ∩ L2 .
3
(2) (a) Construct a state diagram for an NFA M1 to recognize the language over Σ = {a, b}
defined by L1 = {w : the number of as in w is a multiple of 3, and w starts and ends
with the same letter}. Use as few states as you can! (Note: we assume that w has at
least one letter, in order to be able to refer to the ‘first’ letter and the ‘last’ letter.)
Answer:
a
b
b
q1
a
b
q2
a
q3
a
a
b
q0
q7
b
b
a
q4
a
q5
b
q6
b
b
a
(b) Using the method of Theorem 1.39 and your answer to the (a) part, construct a DFA
for L1 .
Answer:
Only the states reachable from the start state are included in the state diagram.
a
b
b
a
{q1}
a
{q2}
a
{q3,q7}
b
{q0}
a
{q3}
b
{q4}
b
b
{q4,q7}
a
a
a
{q5}
s
b
b
4
a
{q6}
b
(c) Construct a state diagram for an NFA M2 to recognize the language over Σ = {a, b}
defined by L2 = {w : w starts with an a and ends with a b}. Use as few states as you
can!
Answer:
a,b
q8
a
q9
b
q10
(d) Using the method of Theorem 1.39 and your answer to the (c) part, construct a DFA
for L2 .
Answer:
Only the states reachable from the start state are included in the state diagram.
a
b
b
{q8}
b
a
{q9}
∅
{q9,q10}
a
a,b
5
(e) Using the method in Theorem 1.45 and your answers to the (a) and (c) parts, construct
a state diagram for an NFA M3 to recognize the language over Σ = {a, b} defined by
L3 = L1 ∪ L2 .
Answer:
a
b
b
q1
a
b
q2
a
q3
a
a
b
q0
q7
b

b
a
q4
a
q5
q6
q0'
b

b
a,b
a
q8
b
a
b
q9
q10
(f) Using the method of Theorem 1.47 and your answers to the (a) and (c) parts, construct
a state diagram for an NFA M4 to recognize the language over Σ = {a, b} defined by
L4 = L1 L2 .
Answer:
a
b
a
q1
b
b
q2
a
a,b
q3
a
a
b
q0

q7
b
b
q4
b
a
a
q5
b
q6
b
a
6
q8
a
q9
b
q10
(g) By whatever method you like, construct a state diagram for an NFA M5 to recognize
the language over Σ = {a, b} defined by L5 = L1 ∩ L2 . Use as few states as you can!
Explain your method.
Answer:
Since for a string w to be in L1 it must begin and end with the same letter, while
to be in L2 it must begin with an a and end with a b, there are no strings that can be
in both L1 and L2 . Therefore, L5 = L1 ∩ L2 = ∅, whose state diagram is given below.
q0
(3) Sipser 1.15, page 85.
Answer:
The main difference between the construction proposed in the problem and the one given
in Theorem 1.49 is that the construction in this problem does not create a new start state.
That is what we will use in the construction of a counterexample. Let N1 be the machine
given by the following state diagram:
a
q0
b
q1
Then A1 = {ai b : i ≥ 0}, in other words, 0 or more as followed by a single b. Note that
since everything in A1 ends with a b, then everything in A∗1 exept for also ends in a b. In
particular, the string a ∈
/ A∗1 . Following the construction given in the problem, we generate
the NFA N given by its state diagram:
a

q0
b
q1
It is clear from the state diagram that a is in the language recognized by N , L(N ). Since
a ∈ L(N ) but a ∈
/ A∗1 , L(N ) 6= A∗1 . Therefore N does not recognize A∗1 .
7
(4) Sipser 1.16, page 86.
Answer:
(a)
{1}
b
a,b
{1,2}
a
b
{2}
∅
a
a,b
(b) Only the states reachable from the start state are included in the state diagram.
b
{1,2}
a
a,b
∅
a
{1,2,3}
b
{2,3}
b
a
(5) Sipser 1.24 and 1.25, page 87.
Answer:
1.24
a. 000
b. 111
c. 011
d. 0101
e. 1
f. 1111
g. 110110
h. 8
1.25
A finite state transducer (FST) is a 5-tuple (Q, Σ, δ, q0 , Γ), where
1.
2.
3.
4.
5.
Q is a finite set called the states,
Σ is a finite set called the input alphabet,
δ : Q × Σ −→ Q × Γ is the transition function,
q0 ∈ Q is the start state, and
Γ is a finite set called the output alphabet.
A computation of an FST F = (Q, Σ, δ, q0 , Γ) on input w = w1 w2 . . . wn ∈ Σ∗ outputs
x = x1 x2 . . . xn ∈ Γ∗ iff there exists a sequence of states r0 , r1 , . . . , rn in Q such that
1. r0 = q0 , and
2. δ(ri , wi+1 ) = (ri+1 , xi+1 ) for 0 ≤ i < n.
Suggestion: Another exercise that is well worth doing is Sipser 1.14, page 85. This is not to be
handed in for grading, however.
Solution:
a.
Let M = (Q, Σ, δ, q0 , F ) be a DFA such that L(M ) = B. Also, let M 0 = (Q, Σ, δ, q0 , Q \ F ).
This problem asks us to show that B = L(M 0 ). w1 w2 . . . wn = w ∈ B iff there is a computation
consisting of states r0 , r1 , . . . , rn in Q such that r0 = q0 , δ(ri , wi+1 ) = ri+1 for 0 ≤ i < n, but such
that rn ∈
/ F iff rn ∈ Q \ F iff r0 , r1 , . . . , rn is an accepting computation for M 0 iff w ∈ L(M 0 ).
This shows that B = L(M 0 ). Since for every regular language there exists a finite automaton that
recognizes its complement (constructed by M 0 ), we conclude that the class of regular languages is
closed under complement.
9
b.
Let M be the NFA given by the following state diagram:
a,b
q0
q1
b
Then C = L(M ) = {w : w ends with a b}. Therefore C = {w : w does not end with a b}. In
particular the string b ∈
/ C. Swapping the accept and non-accept states of M gives the NFA M 0
given by the floowing state diagram:
a,b
q0
b
q1
Clearly, L(M 0 ) = Σ∗ , that is every string over Σ which includes b. However, then b ∈ L(M 0 ), but
b∈
/ C. Therefore, L(M 0 ) 6= C. Thus, swapping the accepting and non-accepting states of an NFA
does not give an NFA that recognizes the complement of the original.
However, the class of languages recognized by NFAs is closed under complement. The class of
languages accepted by NFAs is the same as the class of languages accepted by DFAs, the class
of regular languages as shown by Theorem 1.39. Part (a) of this problem showed that regular
languages are closed under complement. Thus, the class of languages recognized by NFAs is closed
under complement. (One could always covert the NFA to an equivalent DFA and then swap the
accepting and non-accepting states to produce a DFA (and hence NFA) that recognizes the complement of the original NFA).
10