CSE 396 Introduction to the Theory of Computation Homework Solution - Set 3 Due: Friday 9/19/08 1. Textbook, Page 83, Exercise 1.4. (a) i. {w| w has at least three a’s} b b a A a B a,b b a C D ii. {w| w has at least two b’s} a b 1 a,b a b 2 3 iii. {w| w has at least three a’s and at least two b’s} 1A a 1B b 2A a 2B a 3B a 1D b a 2C b b (b) 1C b b 3A a b a 2D b a 3C b a a b a 3D a,b b i. {w| w has exactly two a’s} b A b a B a,b b a C a D ii. {w| w has at least two b’s} a b 1 1 a,b a 2 b 3 Fall 2008 iii. {w| w has exactly two a’s and at least two b’s} a 1A b a a a b a 2D b a 3B a b a 3C b a b 2C b 3A 1D b 2B b a 1C b 2A (c) a 1B 3D a,b b i. {w| w has an even number of a’s} b a 1 b 2 a ii. {w| w has one or two b’s} a A a b B a,b a b C D iii. {w| w has an even number of a’s and one or two b’s} b 1A a a 2A (d) b 1B a b a 2B b 1C a b a 2C 1D a b a 2D i. {w| w has an even number of a’s} b a 1 b 2 a ii. {w| each a in w is followed by at least one b} a,b b a A B b 2 a C b b iii. {w| w has an even number of a’s and each a is followed by at least one b} b b b 1A 1B 1C a a a a a 2A (e) 2B b a 2C b b a,b a,b i. {w| w starts with an a} b 1 a 2 3 ii. {w| w has at most one b} a b A a,b a b B C iii. {w| w starts with an a and has at most one b} a 1A b 1B b b 1C b b 2A 2B 2C a a a 3A b a (f) a,b a 3B a b 3C a,b i. {w| w has an odd number of a’s} b a 1 2 a ii. {w| w ends with a b} 3 b a b b A B a iii. {w| w has an odd number of a’s and ends with a b} b 1A a a 2A (g) 1B b a a 2B b b i. {w| w has even length} a,b A B a,b ii. {w| w has an odd number of a’s} b a b 1 2 a iii. {w| w has even length and an odd number of a’s} 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 1 2 (b) The language of Exercise 1.6c with five states 4 0 3 0,1 1 0 0,1 1 2 0 3 1 4 5 (c) The language of Exercise 1.6l with six states 1 0 1 2 λ 3 0 1 0 λ 0 4 1 5 1 0 2 0 1 6 (d) The language {0} with two states (e) The language 0∗ 1∗ 0+ with three states 0 1 λ 1 2 0 0 3 (f) The language 1∗ (001+ )∗ with three states 2 0 1 0 1 1 (g) The language {ε} with one state 1 (h) The language 0∗ with one state 5 3 0 1 3. Textbook, Page 85, Exercise 1.11. Prove that every NFA can be converted to an equivalent 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} ΣΣ0Σ∗ (e) {w| w starts with 0 and has odd length, or starts with 1 and has even length} (0 ∪ 1Σ)(ΣΣ)∗ (f) {w| w doesn’t 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} 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, ε 8