You are on page 1of 8

CSE 396 Introduction to the Theory of Computation Fall 2008

Homework Solution - Set 3


Due: Friday 9/19/08

1. Textbook, Page 83, Exercise 1.4.


(a) i. {w| w has at least three as}

b b b a,b
a a a
A B C D

ii. {w| w has at least two bs}

a a a,b
b b
1 2 3

iii. {w| w has at least three as and at least two bs}

a a a
1A 1B 1C 1D a

b b b b
a a a
2A 2B 2C 2D a

b b b b
a a a
3A 3B 3C 3D a,b

b b b

(b) i. {w| w has exactly two as}

b b b a,b
a a a
A B C D

ii. {w| w has at least two bs}

a a a,b
b b
1 2 3

1
iii. {w| w has exactly two as and at least two bs}

a a a
1A 1B 1C 1D a

b b b b
a a a
2A 2B 2C 2D a

b b b b
a a a
3A 3B 3C 3D a,b

b b b

(c) i. {w| w has an even number of as}

b a b

1 2
a

ii. {w| w has one or two bs}

a a a a,b
b b
A B C D

iii. {w| w has an even number of as and one or two bs}

b b b
1A 1B 1C 1D b

a a a a a a a a
b b b
2A 2B 2C 2D b

(d) i. {w| w has an even number of as}

b a b

1 2
a

ii. {w| each a in w is followed by at least one b}

b a a,b
a
A B C
b

2
iii. {w| w has an even number of as and each a is followed by at least one b}

b b

b
1A 1B 1C
a a
a a
a a
2A b 2B 2C

b b

(e) i. {w| w starts with an a}

a,b a,b
b a
1 2 3

ii. {w| w has at most one b}

a a a,b
b b
A B C

iii. {w| w starts with an a and has at most one b}

a a a,b
b b
1A 1B 1C
b b
b

2A 2B 2C
a a a
b b
3A 3B 3C
a a a,b

(f) i. {w| w has an odd number of as}

b a b

1 2
a

ii. {w| w ends with a b}

3
a b
b
A B
a

iii. {w| w has an odd number of as and ends with a b}

b
1A 1B
a b
a a
a

2A b 2B
b

(g) i. {w| w has even length}

a,b
A B
a,b

ii. {w| w has an odd number of as}

b a b

1 2
a

iii. {w| w has even length and an odd number of as}

b
1A 1B
b
a a a a
b
2B 2A
b

2. Textbook, Page 84, Exercise 1.7.


(a) The language {w| w ends with 00} with three states

0,1
0 0
1 2 3

(b) The language of Exercise 1.6c with five states

4
0,1 0,1
0 1 0 1
1 2 3 4 5

(c) The language of Exercise 1.6l with six states

1 0 1


2 3
0
1 0 0 0
1 1
4 5 6

(d) The language {0} with two states

0
1 2

(e) The language 0 1 0+ with three states

0 1 0
0
1 2 3

(f) The language 1 (001+ ) with three states

2
0 0

1 1 3
1

(g) The language {} with one state

(h) The language 0 with one state

5
0

3. Textbook, Page 85, Exercise 1.11. Prove that every NFA can be converted to an equiv-
alent one that has a single accept state.

As discussed in class, create a single new final state. Create -edges from the original
final states to this new final state. Make the original final states non-final. If the
processing of an input word completes in one of the original final states, the new final
state is immediately accessible without any additional symbols. Furthermore, the only
way to access the new final state is if the processing completes in one of the original
final states. Hence, all words previously accepted will remain accepted and no additional
words will be accepted, meaning the two machines accept the same language and are
therefore equivalent.

4. Textbook, Page 86, Exercise 1.18. Give regular expressions generating the languages of
Exercise 1.6.
(a) {w| w begins with a 1 and ends with a 0}

1 0

(b) {w| w contains at least three 1s}

1 1 1

(c) {w| w contains the substring 0101, i.e., w = x0101y for some x and y}

0101

(d) {w| w has length at least 3 and its third symbol is a 0}

(e) {w| w starts with 0 and has odd length, or starts with 1 and has even length}

(0 1)()

(f) {w| w doesnt contain the substring 110}

6
0 (10+ ) 1

(g) {w| the length of w is at most 5}

( )5

(h) {w| w is any string except 11 and 111}

0 10 0 10 110 3 +

(i) {w| every odd position of w is a 1}

(1) ( 1)

(j) {w| w contains at least two 0s and at most one 1}

00+ 100+ 0+ 10+ 00+ 1

(k) {, 0}

(l) {w| w contains an even number of 0s, or contains exactly two 1s}

1 (01 01 ) 0 10 10

(m) The empty set

(n) All strings except the empty string

5. Textbook, Page 86, Exercise 1.20.


(a) a b

Members: ab, abb


Not members: ba, bba

7
(b) a(ba) b

Members: ab, ababab


Not members: aba, bab

(c) a b

Members: aaa, bbb


Not members: aabb, bbaa

(d) (aaa)

Members: aaa, aaaaaa


Not members: a, aaaa

(e) a b a

Members: aba, bbaaabaabb


Not members: a, b

(f) aba bab

Members: aba, bab


Not members: ababab, ba

(g) ( a)b

Members: b, ab
Not members: a, ba

(h) (a ba bb)

Members: a, bbab
Not members: b,

You might also like