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. Define δ 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.

NFA N1 accepts 1(01)*. 1. The proposed construction to prove the closure of the regular languages under the star operation.2.1. 1.11. . which is not in (1(01)*)*. N1 N ε q2 1 q1 1 0 q2 0 q1 Fig. but NFA N accepts 10.11. The counterexample to show why this construction doesn't work.N1 N ε ε Fig.

b}. Solution a. 2} (See the figure on the page after part b. δN F A . where δDF A is given by δDF A ∅ {1} {2} {1. the constructed DFA is (P ({1. b}. 2} ∅ b {2} {1} ∅ ∅ Using the construction in Theorem 1. 2}. {1}).) .19. {a. 2}). This NFA is ({1. {1. 1. 2} a ∅ {1. where δN F A is given by δN F A 1 2 a {1. {{1}. {1}.1. 2} ∅ {1.12 Use the construction given in Theorem 1.19 to convert the following two nondeterministic finite automata to equivalent deterministic finite automata. {a. δDF A . 2} b ∅ {2} {1} {1. 2}}).

{a. 3}}). {1. 2. where δN F A is given by δN F A 1 2 3 a {3} {1} b ∅ ∅ {2} ∅ ∅ {2} {2. 3} b ∅ ∅ ∅ {2. 1. 3} {2. 3}. 3} ∅ {2. 3} {2. 2. {{2}. 3} {1. 3} {1. 2. 2} {1. 2} {2} {1. δN F A . δDF A . {2}). 3}. {1. b}. the constructed DFA is (P ({1. 3} {2. {2. This NFA is ({1. where δDF A is given by δDF A ∅ {1} {2} {3} {1. 3} Using the construction in Theorem 1. b}.b. 3} (See the figure on the following page. 2. 3} {2. {a. 3} a ∅ {3} {1. 2} {1. 2}.19. 2. 2. {1.) . 3}). 2}.

Original NFA Equivalent DFA a 1 b 2 a. b a b {1.2.2} a.3} {2} b a q {}5 .2} {1. b b {1.12a.3} a a. b b {2} a {} a.3} a. b a b {1} q4 {1.1. b 3 b Equivalent DFA b {3} a {1} a b a b {2. Original NFA a 1 a ε 2 a. b 1.12b.

{w | w starts with 0 and has odd length. a. c. {w | w contains the substring 0101} = Σ∗ 0101Σ∗ . {w | w contains at least three 1s} = Σ∗ 1Σ∗ 1Σ∗ 1Σ∗ . d. i. {w | w contains at least two 0s and at most one 1} = 000∗ ∪ 000∗ 10∗ ∪ 0100∗ ∪ 1000∗ . {w | w doesn’t contain the substring 110} = 0∗ (10)∗ 0∗ ∪ 0∗ 1(00∗ 1)∗ ∪ 0∗ 1(00∗ 1)∗ 11∗ . {w | w begins with a 1 and ends with a 0} = 1Σ∗ 0. e. f. h.13 Give regular expressions generating the languages of Exercise 1. .1. The empty set is generated by ∅. Because the alphabet Σ = {0. { . j. {w | every odd position of w is a 1} = (1Σ)∗ ∪ 1(Σ1)∗ .4. {w | w is any string except 11 and 111} = ∪ 1 ∪ 0Σ∗ ∪ 10Σ∗ ∪ 110Σ∗ ∪ 111ΣΣ∗ . l. A regular expression can be derived by following each accepting path. 1} for each of these languages. each path from the start state to an accept state. take the union of the regular subexpressions to obtain the final regular expression. One way to approach this problem is to start with the DFAs you have already drawn Solution (in HW2) to answer Exercise 1. b. n.4. The language containing all strings except the empty string is generated by ΣΣ∗ . we will write Σ as shorthand for (0 ∪ 1). or exactly two 1s} = 1∗ ∪ (1∗ 01∗ 01∗ )∗ ∪ 0∗ 10∗ 10∗ . {w | the length of w is at most 5} = ∪ Σ ∪ ΣΣ ∪ ΣΣΣ ∪ ΣΣΣΣ ∪ ΣΣΣΣΣ. {w | w contains an even number of 0s. k. {w | w has length at least 3 and its third symbol is a 0} = ΣΣ0Σ∗ . g. m. that is. After all paths have been considered. and writing a regular subexpression for each path. or starts with 1 and has even length} = (0∪1Σ)(ΣΣ)∗ . 0} = ∪ 0.

14a.1. (0 U 1)*000(0 U 1)* 0 0 q4 1 0U1 ε 1 q4 ε 0 1 q4 (0 U 1)* ε ε 1 ε 0 q4 ε 0 q4 q4 ε 0 ε 000 ε 0 q4 (0 U 1)*000(0 U 1)* ε ε ε 1 ε q4 ε ε ε 0 ε ε ε 1 ε q4 ε ε 0 0 q4 ε 0 q4 ε ε 0 q4 .

(((00)*(11)) U 01)* 0 0 q4 1 1 q4 00 0 q4 ε 0 q4 11 1 q4 ε 1 q4 01 0 q4 ε 1 q4 ε (00)* ε 0 q4 ε 0 q4 (00)*(11) ε ε 1 q4 ε 0 q4 ε 0 ε q4 ε 1 q4 ((00)*(11)) U 01 ε ε ε ε 0 q4 ε 1 q4 ε 0 q4 ε 0 ε 1 q4 ε q4 1 q4 (((00)*(11)) U 01)* 0 ε q4 ε ε ε ε 1 0 q4 ε q4 ε 1 ε q4 ε 0 ε q4 ε 1 ε q4 q4 .1.14b.

1. θ* θ q4 ε θ* .14c.

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

1 b 2 b a a S ε b 1 b 2 a A ε a S ε 1 ba* a U ba*b A S (a U ba*b)*ba* A .1.16a.

a.1. b b 3 ε ε A ε aUb b 3 1 2 b a S 1 2 b a a a S ε 2 b 3 aUε A aUb a b U (a(a U b)) ε S (a U b)a*b 3 aUε A (b U (a(a U b)))a*b S ε U ((a U b)a*b((b U (a(a U b)))a*b)*(a U ε)) A .16b.