Csci3255 HW 3
Csci3255 HW 3
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*
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
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 Φ .
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.)
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
abbbb*(a+b)(a+b)*
18. Find regular expressions for the following languages on {a, b}*
a. L = {w: |w| mod 3 = 0} ((a+b)(a+b)(a+b))*
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
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
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
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.
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.