Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Hw3sol1 20

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

University of Central Florida School of Computer Science COT 4210 Fall 2004

Prof. Rene Peralta Homework 3 Solutions (by TA Robert Lee)

1.11. Give a counterexample to show that the following construction fails to prove Theorem 1.24, the closure of the class of regular languages under the star operation. Let N1 = (Q1 , , 1 , q1 , F1 ) recognize A1 . Construct N = (Q1 , , , q1 , F ) as follows. N is supposed to recognize A 1. a. The states of N are the states of N1 . b. The start state of N is the same as the start state of N1 . c. F = {q1 } F1 . The accept states F are the old accept states plus its start state. d. Dene so that for any q Q and any a , (q, a) = Solution See Figure 1.11.1 on the next page for a picture of this formal construction. The primary difference between this construction and the one in Theorem 1.24 is that the original start state becomes an accept state. To create a counterexample, we want to consider a language that does not already accept in its start state. Choose the language A1 = 1(01) . Language A1 is recognized by NFA N1 : N1 = ({q1 , q2 }, {0, 1}, 1 , q1 , {q2 }), where 1 is given by 1 q1 q2 0 { q1 } 1 {q2 } 1 (q, a) q F1 or a = 1 (q, a) {q1 } q F1 and a = .

Using the procedure given in this problem, construct the NFA N to recognize A 1: N = ({q1 , q2 }, {0, 1}, , q1 , {q1 , q2 }), where is given by 1 q1 q2 0 { q1 } 1 {q2 } { q1 }

Both NFA N1 and NFA N are shown in Figure 1.11.2 on the next page. Notice that the con structed machine N accepts the string 10, which is not in the language A 1 = (1(01) ) . Thus N1 is a valid counterexample to prove that this construction does not work.

N1

Fig. 1.11.1. The proposed construction to prove the closure of the regular languages under the star operation.

N1

N q2 1 q1 1 0 q2

0 q1

Fig. 1.11.2. The counterexample to show why this construction doesn't work. NFA N1 accepts 1(01)*, but NFA N accepts 10, which is not in (1(01)*)*.

1.12 Use the construction given in Theorem 1.19 to convert the following two nondeterministic nite automata to equivalent deterministic nite automata. Solution a. This NFA is ({1, 2}, {a, b}, N F A , 1, {1}), where N F A is given by N F A 1 2 a {1, 2} b {2} {1}

Using the construction in Theorem 1.19, the constructed DFA is (P ({1, 2}), {a, b}, DF A , {1}, {{1}, {1, 2}}), where DF A is given by DF A {1} {2} {1, 2} a {1, 2} {1, 2} b {2} {1} {1, 2}

(See the gure on the page after part b.)

b. This NFA is ({1, 2, 3}, {a, b}, N F A , 1, {2}), where N F A is given by N F A 1 2 3 a {3} {1} b {2}

{2} {2, 3}

Using the construction in Theorem 1.19, the constructed DFA is (P ({1, 2, 3}), {a, b}, DF A , {1, 2}, {{2}, {1, 2}, {2, 3}, {1, 2, 3}}), where DF A is given by DF A {1} {2} {3} {1, 2} {1, 3} {2, 3} {1, 2, 3} a {3} {1, 2} {2} {1, 2, 3} {2, 3} {1, 2} {1, 2, 3} b {2, 3} {2, 3} {2, 3} {2, 3}

(See the gure on the following page.)

1.12a. Original NFA

Equivalent DFA a

1 b 2 a, b

a b

{1}

q4 {1,2}

a, b

b
{2}

{}

a, b

1.12b. Original NFA a 1 a 2 a, b 3 b

Equivalent DFA

b
{3}

{1}

a b a

{2,3}

a a, b a

{1,2,3}

a, b b
{1,2} {1,3}

{2}

b a

q {}5

1.13

Give regular expressions generating the languages of Exercise 1.4. One way to approach this problem is to start with the DFAs you have already drawn

Solution

(in HW2) to answer Exercise 1.4. A regular expression can be derived by following each accepting path, that is, each path from the start state to an accept state, and writing a regular subexpression for each path. After all paths have been considered, take the union of the regular subexpressions to obtain the nal regular expression. Because the alphabet = {0, 1} for each of these languages, we will write as shorthand for (0 1). 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} = 0101 . d. {w | w has length at least 3 and its third symbol is a 0} = 0 . e. {w | w starts with 0 and has odd length, or starts with 1 and has even length} = (01)() . f. {w | w doesnt contain the substring 110} = 0 (10) 0 0 1(00 1) 0 1(00 1) 11 . g. {w | the length of w is at most 5} = . h. {w | w is any string except 11 and 111} = 1 0 10 110 111 . i. {w | every odd position of w is a 1} = (1) 1(1) . j. {w | w contains at least two 0s and at most one 1} = 000 000 10 0100 1000 . k. { , 0} = 0. l. {w | w contains an even number of 0s, or exactly two 1s} = 1 (1 01 01 ) 0 10 10 . m. The empty set is generated by . n. The language containing all strings except the empty string is generated by .

1.14a. (0 U 1)*000(0 U 1)* 0


0 q4

1 0U1

q4

q4

(0 U 1)*
1 0 q4 0 q4 q4 0

000

q4

(0 U 1)*000(0 U 1)*
1 q4 0 1 q4 0

q4

q4

0 q4

1.14b. (((00)*(11)) U 01)*


0
0 q4

q4

00

q4

q4

11

q4

q4

01

q4

q4

(00)*

q4

q4

(00)*(11)
1 q4 0 q4 0

q4 1 q4

((00)*(11)) U 01

q4

q4

q4

0 1 q4

q4

q4

(((00)*(11)) U 01)*
0 q4 1 0 q4 q4 1

q4 0 q4 1 q4 q4

1.14c. *
q4

1.15 For each of the following languages, give two strings that are members and two strings that are not membersa total of four strings for each part. Assume the alphabet = {a, b} in all parts. Solution a. a b . Members: , a. Non-members: ba, aba. b. a(ba) b. Members: ab, abab. Non-members: , aa. c. a b . Members: , a. Non-members: ab, ba. d. (aaa) . Members: , aaa. Non-members: a, aa. e. a b a . Members: aba, aaba. Non-members: , a. f. aba bab. Members: aba, bab. Non-members: , a. g. ( a)b. Members: b, ab. Non-members: , a. h. (a ba bb) . Members: a, ba. Non-members: , b.

1.16a.

1 b 2 b

1 b 2

1 ba*

a U ba*b

S (a U ba*b)*ba* A

1.16b. a, b b 3 A aUb b 3

2 b

2 b

S 2 b 3 aU A aUb a b U (a(a U b))

(a U b)a*b

3 aU A

(b U (a(a U b)))a*b

U ((a U b)a*b((b U (a(a U b)))a*b)*(a U ))

You might also like