0% found this document useful (0 votes)
173 views10 pages

355 HW 1 S 11 Sol

This document provides solutions to homework problems for a course on formal languages and automata theory. It includes solutions for constructing state diagrams for deterministic and non-deterministic finite automata that recognize various languages involving combinations of the numbers of 'a's and 'b's in strings. It also addresses questions about the relationships between different language operations and provides examples of state diagrams for NFAs and DFAs.

Uploaded by

burmansoft
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
173 views10 pages

355 HW 1 S 11 Sol

This document provides solutions to homework problems for a course on formal languages and automata theory. It includes solutions for constructing state diagrams for deterministic and non-deterministic finite automata that recognize various languages involving combinations of the numbers of 'a's and 'b's in strings. It also addresses questions about the relationships between different language operations and provides examples of state diagrams for NFAs and DFAs.

Uploaded by

burmansoft
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

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 M
1
to recognize the language over = {a, b}
dened by L
1
= {w : the number of as in w is even}.
Answer:
q0 q1
a
a
b
a
b
(b) Construct a state diagram for a DFA M
2
to recognize the language over = {a, b}
dened by L
2
= {w : the number of bs in w is at most 3}.
Answer:
a a a a a,b
q2 q3 q4 q5 q6
b b b b
(c) Using the method in Theorem 1.25 and your answers to the (a) and (b) parts, construct
a state diagram for a DFA M
3
to recognize the language over = {a, b} dened by
L
3
= {w : the number of as in w is even or the number of bs in w is at most 3}.
Answer:
(q0,q2) (q0,q3) (q0,q4) (q0,q5)
b b b b
(q1,q2) (q1,q3) (q1,q4) (q1,q5) (q1,q6)
b b b b
(q0,q6)
a a a a a a a a a a
b
b
1
(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 M
4
to recognize the language over = {a, b} de-
ned by L
4
= {w : the number of as in w is even and the number of bs in w is at most 3}.
Answer:
(q0,q2) (q0,q3) (q0,q4) (q0,q5)
b b b b
(q1,q6)
b b b b
a a a a a a
a
a a a
b
b
(q1,q6)
(q1,q6) (q1,q6) (q1,q6) (q1,q6) (q1,q6)
(e) By whatever method you like, construct a state diagram for a DFA M
5
to recognize
the language over = {a, b} dened by L
5
= {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 L
5
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}.
q0
b
q5 q1 q2 q3 q4
b b b b
b
a
a
a
a
a
a
2
(f) Consider the three languages L
1
L
2
, L
1
L
2
, and L
1
L
2
. For each pair of these, is
one of the languages contained in the other? Is either properly contained in the other?
Explain.
Solution:
L
1
L
2
is properly contained (and hence contained) in L
1
L
2
. To see containment
note that if w L
1
L
2
then w L
1
so w L
1
L
2
. To see the containment is proper
note the string a is in L
2
and is thus in L
1
L
2
, but a does not have any even number
of as and is thus not in L
1
and so it cannot be in L
1
L
2
. Since L
1
L
2
is properly
contained in L
1
L
2
, L
1
L
2
is not contained in L
1
L
2
.
L
1
L
2
is properly contained in L
1
L
2
. To see containment note that if w L
1
L
2
then w L
1
or w L
2
. If w L
1
, then w = w L
1
L
2
since L
2
. Similarly, if
w L
2
, then w = w L
1
L
2
since L
1
. To see the containment is proper, note that
bbbab L
1
L
2
, since bbb L
1
(has 0 as) and ab L
2
(has 1 b), but bbbab does not have
an even number of as and is thus not in L
1
and bbbab has more than three bs so it is
also not in L
2
. Thus bbbab cannot be in L
1
L
2
. Since L
1
L
2
is properly contained
in L
1
L
2
, L
1
L
2
is not contained in L
1
L
2
.
L
1
L
2
is properly contained in L
1
L
2
. One way to see this is to realize that proper
containment is a transitive property, which means since L
1
L
2
is properly contained
in L
1
L
2
and L
1
L
2
is properly contained in L
1
L
2
, then L
1
L
2
must be properly
contained in L
1
L
2
.
Another way is to proceed as we did above. To see containment note that if w L
1
L
2
then w L
1
and w = w L
1
L
2
since L
2
. To see the containment is proper, note
that a = a L
1
L
2
, but a does not have an even number of as and is thus not in L
1
and so it cannot be in L
1
L
2
. Since L
1
L
2
is properly contained in L
1
L
2
, L
1
L
2
is
not contained in L
1
L
2
.
3
(2) (a) Construct a state diagram for an NFA M
1
to recognize the language over = {a, b}
dened by L
1
= {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 rst letter and the last letter.)
Answer:
q0
q1
q2 q3
q4 q5 q6
q7
a a
a
a
a
a a
b b
b
b
b
b b b
b
a
(b) Using the method of Theorem 1.39 and your answer to the (a) part, construct a DFA
for L
1
.
Answer:
Only the states reachable from the start state are included in the state diagram.
{q0}
{q1}
{q2}
{q6}
a a
a
a
a a
b
b
b
b
b
b
b
a
{q4,q7}
{q3,q7}
{q3}
b a
aa
s {q5}
{q4}
a
b
4
(c) Construct a state diagram for an NFA M
2
to recognize the language over = {a, b}
dened by L
2
= {w : w starts with an a and ends with a b}. Use as few states as you
can!
Answer:
q8 q9 q10
a
a,b
b
(d) Using the method of Theorem 1.39 and your answer to the (c) part, construct a DFA
for L
2
.
Answer:
Only the states reachable from the start state are included in the state diagram.
{q8} {q9} {q9,q10}
a
a
b

b
a
b
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 M
3
to recognize the language over = {a, b} dened by
L
3
= L
1
L
2
.
Answer:
q8 q9 q10
a
a,b
b
q0
q1
q2 q3
q4 q5 q6
q7
a a
a
a
a
a a
b b
b
b
b
b b b
b
a
q0'

(f) Using the method of Theorem 1.47 and your answers to the (a) and (c) parts, construct
a state diagram for an NFA M
4
to recognize the language over = {a, b} dened by
L
4
= L
1
L
2
.
Answer:
q8 q9 q10
a
a,b
b
q0
q1
q2 q3
q4 q5 q6
a a
a
a
a
a a
b b
b
b
b
b b b
b
a

q7
6
(g) By whatever method you like, construct a state diagram for an NFA M
5
to recognize
the language over = {a, b} dened by L
5
= L
1
L
2
. Use as few states as you can!
Explain your method.
Answer:
Since for a string w to be in L
1
it must begin and end with the same letter, while
to be in L
2
it must begin with an a and end with a b, there are no strings that can be
in both L
1
and L
2
. Therefore, L
5
= L
1
L
2
= , whose state diagram is given below.
q0
(3) Sipser 1.15, page 85.
Answer:
The main dierence 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 N
1
be the machine
given by the following state diagram:
q1 q0
a
b
Then A
1
= {a
i
b : i 0}, in other words, 0 or more as followed by a single b. Note that
since everything in A
1
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:
q1
a
b
q0

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) = A

1
. Therefore N does not recognize A

1
.
7
(4) Sipser 1.16, page 86.
Answer:
(a)
{1,2}
a
b
{1}
{2}
b
a,b
a

a,b
(b) Only the states reachable from the start state are included in the state diagram.
a,b
a
{1,2}
b
b
a
{1,2,3}
a
b
{2,3}
(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 nite state transducer (FST) is a 5-tuple (Q, , , q
0
, ), where
1. Q is a nite set called the states,
2. is a nite set called the input alphabet,
3. : Q Q is the transition function,
4. q
0
Q is the start state, and
5. is a nite set called the output alphabet.
A computation of an FST F = (Q, , , q
0
, ) on input w = w
1
w
2
. . . w
n

outputs
x = x
1
x
2
. . . x
n

i there exists a sequence of states r


0
, r
1
, . . . , r
n
in Q such that
1. r
0
= q
0
, and
2. (r
i
, w
i+1
) = (r
i+1
, x
i+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, , , q
0
, F) be a DFA such that L(M) = B. Also, let M

= (Q, , , q
0
, Q \ F).
This problem asks us to show that B = L(M

). w
1
w
2
. . . w
n
= w B i there is a computation
consisting of states r
0
, r
1
, . . . , r
n
in Q such that r
0
= q
0
, (r
i
, w
i+1
) = r
i+1
for 0 i < n, but such
that r
n
/ F i r
n
Q\ F i r
0
, r
1
, . . . , r
n
is an accepting computation for M

i w L(M

).
This shows that B = L(M

). Since for every regular language there exists a nite automaton that
recognizes its complement (constructed by M

), 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:
q1 q0
a,b
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

given by the oowing state diagram:


q0 q1
a,b
b
Clearly, L(M

) =

, that is every string over which includes b. However, then b L(M

), but
b / C. Therefore, L(M

) = 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 com-
plement of the original NFA).
10

You might also like