Вы находитесь на странице: 1из 5

CSCI3255: Math Foundations of CS Homework Chapter 3, page 1 October 2002

3.1/1-11, 17, 18
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)*
CSCI3255: Math Foundations of CS Homework Chapter 3, page 2 October 2002

7. What languages do the regular expressions (Φ *)* and aΦ represent?

According to the definition in the book, X* always contains λ . So (Φ *)* = {λ }, since it clearly can
not contain anything else. aΦ represents the strings that can be formed by concatenating a string from
{a} with a string from Φ . Since Φ doesn’t contain any strings, the answer is Φ .

8. Give a simple verbal description of the language L((aa)*b(aa)* + a(aa)*ba(aa)*).

The set of all strings of a’s and b’s containing exactly one b and an even number of a’s. (Notice that the
two alternatives correspond to having an even number of a’s both before and after the b, or having an
odd number of a’s both before and after the b.)

9. Give a regular expression for LR, where L is the language L((a+b)*b(a+ab)*).

Just reverse the order of the concatenated items: (a+ba)*b(a+b)*

10. Give a regular expression for L = {anbm: n ≥ 1, m ≥ 1, nm ≥ 3}.

Since nm ≥ 3, this can happen when n ≥ 3 or when m ≥ 3 or when n = 2 and n = 2. So we divide the
regular expression into its individual cases:
aaaa*bb* + aa*bbbb* + aabb

11. Find a regular expression for L = {abnw: n ≥ 3, w ∈ {a, b}+}.

abbbb*(a+b)(a+b)*

17. Write a regular expression for the following languages on {0,1}*:


a. all strings ending in 01: (0+1)*01

b. all strings not ending in 01: λ + 0 + 1 + (0 + 1)*(00 + 10 + 11)


(don’t forget those short strings that meet the definition)

c. all strings containing an even number of 0’s: (1*01*01*)* + 1*

d. all strings having at least two occurrences


of the substring 00: (0+1)*00(0+1)*00(0+1)* + (0+1)*000(0+1)*

e. all strings with at most two occurrences


of the substring 00: (1+01)*(λ +00)(1+10)*1(λ +00)(1+10)*
+ (1+01)*000(1+10)*

f. all strings not containing the substring 101: 0*(11*000*)*1*0*


CSCI3255: Math Foundations of CS Homework Chapter 3, page 3 October 2002

18. Find regular expressions for the following languages on {a, b}*
a. L = {w: |w| mod 3 = 0} ((a+b)(a+b)(a+b))*

b. L = {w: na(w) mod 3 = 0} (b*ab*ab*a)*b*

c. 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. We tack on 1, 2, 3, or 4 more.

Chapter 3, Section 2
1. Use the construction shown in class and in the textbook to find an nfa that accepts L(ab*aa + bba*ab)
λ
a λ b λ a a

λ λ
λ

λ
λ λ
b b λ a λ a b

4. Find dfa’s that accept the following languages:


a. L(aa* + aba*b*) a Much easier if you don’t try the
b
a a b algorithmic construction for an
a b b nfa as we did in problem 1.
Convince yourself that the given
b a machine is a dfa and that it
recognizes the language.
a,b

b. L(ab(a+ab)*(a + aa)) a b
a
q0 {q1} {}
a q3
a b {q2
q0 q1 q2 q1 {}
b }
{q2,q3,
a q2 {}
q4 q5 q4}
a {q2
q3 {}
}
b q4 {q5} {}
a Q1 a Coming up with an
Q0 Q2 a q5 {} nfa,{}
though not by
a
Q234 Q2345 algorithm, is much
a b
b b easier in this case.
Qφ b
a,b
CSCI3255: Math Foundations of CS Homework Chapter 3, page 4 October 2002

5. Find dfa’s that accept the following languages:


a. L = L(ab*a*) ∪ L((ab)*ba)
a
q1 q2
a b a
q0 b
a q3 b a
q4 b q5 q6
a

b. 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.
The first language strings must begin with an a. The second language strings must end with an a.
Furthermore, according to the first language the only symbols allowed in between are b's. All these
conditions can only be met if the second language string is abba. So L = {abba}.

b b a
a

a a b
a,b
b

Chapter 3, Section 3
1. Construct a dfa that accepts the language generated by the grammar
S → abA, A → baB, B → aA | bb

a b b a b b
S A B
a a a a
b b a,b

a,b
CSCI3255: Math Foundations of CS Homework Chapter 3, page 5 October 2002

2. Find a regular grammar that generates the language L(aa*(ab + a)*).


S → aA, A → aA | B, B → abB | aB | λ
Starting with the start symbol S, we can generate 1 or more a’s followed by the variable A. By changing
the variable to B, we can now additionally generate zero or more ab’s or a’s.

3. Construct a left-linear grammar for the grammar in Exercise 1.


The grammar in Exercise 1, generates the regular expression (abba)(aba)*bb. Working from right-to-
left, we would get:
S → Cbb, C → Caba | abba

5. Construct a right-linear grammar for L((aab*ab)*).


S → aaA | λ , A → bA | abS.
Generate aaA. Let A generate zero or more b’s. When done, generate the final ab and start over again.

6. Find a regular grammar that generates the language on Σ = {a, b} consisting of all strings with no more
than three a’s.
S → bS | aA | λ , A → bA | aB | λ , B → bB | aC | λ , C → bC | λ
The four variables represent 0, 1, 2 and 3 a’s generated so far. The λ ’s allow us to stop early.

9. Find a left-linear grammar for the language in Excercise 5.


S → Aab | λ , A → Ab | Saa

12. Find regular grammars for the following languages on {a, b}:
a. L = {w: na(w) and nb(w) are both even}.
S → aAoe | bAeo | λ , Aoe → aS | bAoo, Aeo → aAoo | bS, Aoo → aAeo | bAoe
S stands for even a’s and even b’s. The other variables are self-explanatory.

b. L = {w: (na(w) - nb(w)) mod 3 = 1}.


S → aA1 | bA2, A1 → aA2 | bS | λ , A2 → aS | bA1
S represents the modulo value of 0, A1 a value of 1 and A2 a value of 2.

c. L = {w: (na(w) - nb(w)) mod 3 ≠ 0}. (and therefore equals either 1 or 2)


S → aA1 | bA2, A1 → aA2 | bS | λ , A2 → aS | bA1 | λ

d. L = {w: |na(w) - nb(w)| is odd}.


S → aAoe | bAeo, Aoe → aS | bAoo | λ , Aeo → aAoo | bS | λ , Aoo → aAeo | bAoe

Вам также может понравиться