# CSCI3255: Math Foundations of CS 3.

1/1-11, 17, 18

Homework Chapter 3, page 1

October 2002

1. Find all strings in L((a+b)*b(a+ab)*) of length less than four. Length 0: none, since there must be at least one b. Length 1: b Length 2: ab, bb, ba (aa is not possible) Length 3: aab, aba, abb, baa, bab, bba, bbb. (aaa is not possible) 2. Does the expression ((0+1)(0+1)*)*00(0+1)* denote the language of strings w such that w has at least one pair of consecutive zeros? This requires you to understand basic things about regular expressions. x x* represents one or more x’s. So (0+1)(0+1)* represents items, each one of which is either a 0 or a 1. So this is all strings of zeros and ones of length 1 or greater. But when you apply * to this expression, you are now including λ making the expression ((0+1)(0+1)*)* the same as (0+1)*. So the expression as a whole represents any string that consists of 0’s and 1’s with a 00 somewhere in it. Therefore the answer to this question is YES. 3. Show that r = (1 + 01)*(0 + 1*) also denotes the language of strings w such that w has no pair of consecutive zeros. Find two other expressions for this language. It should be clear that (1 + 01)* forces every 0 to be followed by a 1, which is usually necessary for this language. The only exceptions are a 0 at the very end of the string, or any string that has no 0’s (all 1’s). So this expression DOES represent the language in question. Other possibilities might be (1 + 01)*(0 + λ ) + 1* or (1 + 01)* + (1 + 01)*0 + 1* 4. Find a regular expression for {anbm: n ≥ 3, m is even}. n ≥ 3 can be represented by the expression (aaa)a* or, more, simply aaaa* and m is even can be represented by the expression (bb)*. So, overall, the expression aaaa*(bb)* would represent this language. 5. Find a regular expression for {anbm: (n + m) is even}. n + m is even in only two cases: when both n and m are even, or when both are odd. Therefore the expression (aa)*(bb)* + a(aa)*b(bb)* would represent this language. 6. Give a regular expression for each of the following: a. L1 = {anbm: n ≥ 4, m ≤ 3} (aaaa)a*(λ +b+bb+bbb) b. L2 = {anbm: n < 4, m ≤ 3} (λ +a+aa+aaa) (λ +b+bb+bbb) c. The complement of L1 n < 4 or m > 3 or not in the proper form: an a can follow a b. (λ +a+aa+aaa)b* + a*(bbbb)b* + (a+b)*ba(a+b)* d. The complement of L2 n ≥ 4 or m ≥ 4 or not in the proper form: (an a can follow a b). (aaaa)a*b* + a*(bbbb)b* + (a+b)*ba(a+b)*

The set of all strings of a’s and b’s containing exactly one b and an even number of a’s. w ∈ {a. m ≥ 1.CSCI3255: Math Foundations of CS Homework Chapter 3. What languages do the regular expressions (Φ *)* and aΦ represent? According to the definition in the book.) 9. Since Φ doesn’t contain any strings.1}*: a. where L is the language L((a+b)*b(a+ab)*). Write a regular expression for the following languages on {0. X* always contains λ . all strings having at least two occurrences of the substring 00: e. (Notice that the two alternatives correspond to having an even number of a’s both before and after the b. Give a regular expression for L = {anbm: n ≥ 1. all strings with at most two occurrences of the substring 00: (0+1)*00(0+1)*00(0+1)* + (0+1)*000(0+1)* (1+01)*(λ +00)(1+10)*1(λ +00)(1+10)* + (1+01)*000(1+10)* f. Find a regular expression for L = {abnw: n ≥ 3. the answer is Φ . So (Φ *)* = {λ }. abbbb*(a+b)(a+b)* 17. 8. all strings not ending in 01: λ + 0 + 1 + (0 + 1)*(00 + 10 + 11) (don’t forget those short strings that meet the definition) c. Give a simple verbal description of the language L((aa)*b(aa)* + a(aa)*ba(aa)*). So we divide the regular expression into its individual cases: aaaa*bb* + aa*bbbb* + aabb 11. this can happen when n ≥ 3 or when m ≥ 3 or when n = 2 and n = 2. or having an odd number of a’s both before and after the b. all strings ending in 01: (0+1)*01 b. b}+}. all strings not containing the substring 101: 0*(11*000*)*1*0* . since it clearly can not contain anything else. Give a regular expression for LR. nm ≥ 3}. aΦ represents the strings that can be formed by concatenating a string from {a} with a string from Φ . Just reverse the order of the concatenated items: (a+ba)*b(a+b)* 10. page 2 October 2002 7. all strings containing an even number of 0’s: (1*01*01*)* + 1* d. Since nm ≥ 3.

3.b a b Much easier if you don’t try the algorithmic construction for an nfa as we did in problem 1. Find regular expressions for the following languages on {a. b. is much easier in this case. Find dfa’s that accept the following languages: a.CSCI3255: Math Foundations of CS Homework Chapter 3. Section 2 1. b}* a. We tack on 1. q4} {} b {} {q2 } {} Q0 b a. page 3 October 2002 18. L(aa* + aba*b*) a a a b a b b b a. L = {w: |w| mod 3 = 0} ((a+b)(a+b)(a+b))* b. Chapter 3. Convince yourself that the given machine is a dfa and that it recognizes the language. L = {w: na(w) mod 3 = 0} (b*ab*ab*a)*b* c. . 2. L = {w: na(w) mod 5 > 0} (b*ab*ab*ab*ab*a)*(b*ab* + b*ab*ab* + b*ab*ab*ab* + b*ab*ab*ab*ab*) The first part generates multiples of 5 a’s.b a a Qφ Q1 b Q2 b {q2 } {q5} {} Coming up with an {} nfa.q3. or 4 more. though not by {} a algorithm. L(ab(a+ab)*(a + aa)) q0 a q1 b q2 a a b a q4 a a b b Q234 q5 q3 q0 q1 q2 q3 a q4 q5 Q2345 a {q1} {} {q2. Use the construction shown in class and in the textbook to find an nfa that accepts L(ab*aa + bba*ab) λ a λ λ b λ λ λ b b λ λ a λ a b λ a a λ λ 4.

B → aA | bb S a b a a.CSCI3255: Math Foundations of CS Homework Chapter 3.b Chapter 3.b b . Construct a dfa that accepts the language generated by the grammar S → abA. according to the first language the only symbols allowed in between are b's. The first language strings must begin with an a. Furthermore. Find dfa’s that accept the following languages: a. All these conditions can only be met if the second language string is abba. The second language strings must end with an a. L = L(ab*a*) ∪ L((ab)*ba) a q2 q1 a b a q0 b a a q3 b q6 q4 b q5 a b.b b a A b b a a b B a a. page 4 October 2002 5. So L = {abba}. Section 3 1. A → baB. L = L(ab*a*) ∩ L((ab)*ba) The intersection of these two sets can be seen as follows. The only way a string could satisfy the conditions of the first language and the second language is if the string begins and ends with an a. a a b b a b b a a.

S → aAoe | bAeo. B → bB | aC | λ . L = {w: |na(w) . A2 → aS | bA1 S represents the modulo value of 0. b}: a. A → bA | aB | λ . A1 → aA2 | bS | λ . Aoo → aAeo | bAoe S stands for even a’s and even b’s. S → aaA | λ . B → abB | aB | λ Starting with the start symbol S. Aeo → aAoo | bS | λ . S → aAoe | bAeo | λ . 1. The λ ’s allow us to stop early. S → bS | aA | λ . 9. The grammar in Exercise 1. Let A generate zero or more b’s. Find regular grammars for the following languages on {a. A2 → aS | bA1 | λ d. c. 3. A → bA | abS. Aoe → aS | bAoo | λ . Working from right-toleft. A1 → aA2 | bS | λ . S → Aab | λ . A → aA | B. L = {w: na(w) and nb(w) are both even}. When done. page 5 October 2002 2. Construct a left-linear grammar for the grammar in Exercise 1. b. generates the regular expression (abba)(aba)*bb.nb(w)) mod 3 ≠ 0}. Find a left-linear grammar for the language in Excercise 5. Aoe → aS | bAoo. Aoo → aAeo | bAoe . Generate aaA. S → aA. we can now additionally generate zero or more ab’s or a’s.nb(w)| is odd}. Find a regular grammar that generates the language on Σ = {a. Find a regular grammar that generates the language L(aa*(ab + a)*). (and therefore equals either 1 or 2) S → aA1 | bA2. C → Caba | abba 5. we can generate 1 or more a’s followed by the variable A. S → aA1 | bA2. L = {w: (na(w) . Construct a right-linear grammar for L((aab*ab)*). Aeo → aAoo | bS. A → Ab | Saa 12. C → bC | λ The four variables represent 0. L = {w: (na(w) . b} consisting of all strings with no more than three a’s. A1 a value of 1 and A2 a value of 2. 6.nb(w)) mod 3 = 1}. The other variables are self-explanatory. By changing the variable to B. generate the final ab and start over again. we would get: S → Cbb.CSCI3255: Math Foundations of CS Homework Chapter 3. 2 and 3 a’s generated so far.