CS 341
Homework 2
Answers
Chapter 2
1)
Consider the language
L
= {
1
n
2
n
:
n
> 0}.
Is the string 122 in
L
?
No.
Every string in
L
must have the same number of
1
’s as
2
’s.
2)
Let
L
1
= {
a
n
b
n
:
n
> 0}.
Let
L
2
= {
c
n
:
n
> 0}.
For each of the following strings, state whether or not it is an
element of
L
1
L
2
:
a)
ε
.
No.
b)
aabbcc
.
Yes.
c)
abbcc
.
No.
d)
aabbcccc
.
Yes.
3)
Let
L
1
= {
peach
,
apple
,
cherry
} and
L
2
= {
pie
,
cobbler
,
ε
}.
List the elements of
L
1
L
2
in lexicographic
order.
apple
,
peach
,
cherry
,
applepie
,
peachpie
,
cherrypie
,
applecobbler
,
peachcobbler
,
cherrycobbler
(We list the items shortest first.
Within a given length, we list the items
alphabetically.)
4)
Let
L
= {
w
∈
{
a
,
b
}* : 
w

≡
3
0}.
List the first six elements in a lexicographic enumeration of
L
.
ε
,
aaa
,
aab
,
aba
,
abb
,
baa
5)
Consider the language
L
of all strings drawn from the alphabet {
a
,
b
} with at least two different substrings of
length 2.
a)
Describe
L
by writing a sentence of the form
L
= {
w
∈
Σ
* :
P
(
w
)}, where
Σ
is a set of symbols and
P
is a
firstorder logic formula.
You may use the function 
s
 to return the length of
s
.
You may use all the
standard relational symbols (e.g., =,
≠
, <, etc.), plus the predicate
Substr
(
s
,
t
), which is
True
iff
s
is a
substring of
t
.
L
= {
w
∈
{
a
,
b
}* :
5
x
,
y
(
x
≠
y
∧

x
 = 2
∧

y
 = 2
∧
Substr
(
x
,
w
)
∧
Substr
(
y
,
w
))}.
b)
List the first six elements of a lexicographic enumeration of
L
.
aab
,
aba
,
abb
,
baa
,
bab
,
bba
6)
For each of the following languages
L
, give a simple English description of
L
.
Show two strings that are in
L
and two that are not (unless there are fewer than two strings in
L
or two not in
L
, in which case show as many as
possible).
a)
L
= {
w
∈
{
a
,
b
}* : exactly one prefix of
w
ends in
a
}.
L
is the set of strings composed of zero or more
b
’s and a single
a
.
a
,
bba
and
bbab
are in
L
.
bbb
and
aaa
are not.
b)
L
= {
w
∈
{
a
,
b
}* : all prefixes of
w
end in
a
}.