






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







CS 173: Midterm Exam 2
Fall 2004
Name:
NetID:
Lecture Section:
General Directions
Question Points Out of
1 5
2 5
3 5
4 5
5 5
6 5
7 5
8 5
9 10
10 10
11 10
12 10
13 20
Total 100
Multiple Choice
Problem 1 (5pts)
Given the inductive definition:
,
, and
for
,
is:
a) 8
b) 14
c) 34
d) 36
Solution
. The answer is c.
Problem 2 (5pts)
is a collection of strings of symbols. It is recursively defined by
.
, so does :;.
Which of the following does NOT belong to
?
a) 8 <9=9>
b) 9 =9=
c) 9?
d) 8
Solution
”a” is never concatenated onto the end of any string using the rules provided. Therefore, c does not belong.
Problem 6 (5pts)
The harmonic numbers []\ , ^
HM`, are defined by
[a\
_b
HM`Let
and c be two natural numbers, which of the following is equal to the expression:
!Qb
HM`d
e
MH`e c
f
a) [hg ij
[Zj
b) [Zg ij
[Zg
c) [ gij
[ j
d) [ gij
[ g
Solution
!Qblk D
lk W
CMH`mk g
N k g 6i k
k g6i D
HM k g 6ij nbok D
lk W
CMM`pk g
Q/nk D
lk W
MM`P k g i j
[Zg
[Zg ij
[Zg ij
[hg
The correct answer is b.
Problem 7 (5pts)
When sorted in decreasing order of growth rate, which one of the following functions would be first?
a)
XdC=QbFMG IW2
b)
h+6DFHGI
c) q
g 6rQi ks^ q
(^) g6rQi Ws q
grVit s g q
gri Ds q
griu s
d)
6DB XvFHGI,D/C
Solution
a)
XdC=QbFMG IW2 L
vFHGIB
b)
h+6DFHGIw L
c) q
g 6rQi ks^ q
(^) g6rQi Ws q
grVit s g q
gri Ds q
griu s
xyX (^) t L
d)
6DB XvFHGI,D/C L
vFMG Ib
Therefore, b grows the fastest out of the choices.
Problem 8 (5pts)
How many numbers must be selected from the set z
in order to guarantee that at least
one pair adds up to 22?
a) 5
b) 6
c) 7
d) 8
Solution
There are 10 elements, which means 5 pairs. There are 5 pairs of elements that add up to 22 (pigeonholes). So, if
you select 6 elements (pigeons), you are assured to get at least one pair that adds up to 22. Therefore, b is the correct
answer.
Problem 10 (10pts)
Use the definition of big-O to show that for any positive integer constants 8 and 9 ,
?b U
.
You may use the binomial theorem: @h! (^) g (^) gMR g q
g.
s
g .
Solution
To show
e 8
, we should prove both
e 8
and
Ve 8
.
firstly. 8 is positive, thus
for all
. Further, because 9 is positive, we have
Qw 8
Zl
. Thus, let
and
, we have
for any
. That is L
.
. When
, we have
. Thus
X (^) o (^)
. Let
and
8 , we have
d 8
for all
. That is
e 8
.
Thus,
h 8
.
Criteria
d 8
or expand incorrectly: 2 points off.
is dominant by
after expanding
, then getting
or
: 1 point off for each. If without expanding
d 8
and getting the two inequities, 3 points off for each.
Problem 11 (10pts)
Prove using induction that every convex polygon with
vertices has exactly
g q
g . Ws D diagonals.
(A convex polygon is a polygon with the property that every line segment drawn between any two points inside the
polygon lies entirely inside the polygon.)
Solution
Looking over the problem, we first identify the set of objects that we will induct on - the set of all convex polygons
with
vertices. The property we wish to prove is that all such polygons possess
g q
g . Ws D diagonals. We prove this
by induction on the number of vertices as follows:
Base Case: A triangle, by inspection, has
diagonals. Likewise, for
, our formula produces
q
s D
q
s D
diagonals.
Inductive Hypothesis: We can assume either the strong or weak inductive hypothesis. In this case, we assume that a
convex polygon with
vertices has
g q
g . Ws D diagonals.
Inductive Step: We wish to show that a convex polygon with
;l vertices possesses q
g 6i kQs^ q
(^) g. Ds D diagonals. To
do this, we need to relate the
vertex polygon back to a polygon of
vertices. We observe that if we add a vertex
to an
vertex polygon, the new vertex produces
a diagonals (one line segment to each of the other vertices, minus
the one to the right and the one to the left, since these become sides). Further, another diagonal is produced - the one
between the vertices on either side of the new vertex. This means that
diagonals are added every time a vertex
is added, so a8S.
h$P ] 8S.
. But, we know from our inductive hypothesis that the
number of diagonals in an
vertex polygon is
g q
g . Ws D , so ] 8S<
(w (^) g q
(^) g. Ws D
^ g6r> Wg D
Dg. D D
g6r= Wg6i Dg. D D
g6r>Eg. D D
q
g6i^ kQs^ q
(^) g. Ds D
. This completes our proof.
Criteria
diagonals, points to figuring out that the side vertices produced another diagonal, and points for correct math after that point.
point. Some people proved multiple base cases, and received full credit as long as the triangular case was proved, since this did not adversely affect the proof.
diag- onals, but failed to justify it. The justification is absolutely critical, since without it there is no way to relate an $ vertex polygon to an
vertex polygon, and therefore no way to apply the inductive hypothesis. This lost
diagonals, but justified it incorrectly by stating that the addition of a vertex created
diagonals, and applying it to
to get
d O a new diagonals. This lost
points total.
point, unless the person
used circular reasoning to show that q
g 6i kQs^ q
(^) g. Ds D
q
g6i kQs^ q
(^) g. Ds D , which lost points.
Long Problem
Problem 13 (20pts)
A certain set
of integers is defined recursively by the following rules:
, then
and
are in
.
a) What is the largest integer not in
? (8 points)
b) Let ^ be your answer to part a). Prove that all integers ^
and greater are in
. (12 points) ( HINT: Use induction with a basis consisting of the integers ^
through ^
.)
Solution
a) 23 is the largest integer not in
.
b) This can be proved using Strong Induction.
Basis step: X-a (') (¤O') . * (') . 6+5 ('3b¤O'/% . ¤v ('b-3¤O'3 . 6{5$¤O'b- . According to the definition of set
, 24, 25, 26, 27 and 28 are all in
.
Inductive step: Suppose for
, is in set
. Now check
. It can be rewritten as
. Notice that
is either one of the base cases or one of the ’s, where
. In both cases,
is in
. According to the definition rule 2,
, i.e.
is in set
.
Criteria
. With/without explanations are both OK. If your solution is wrong (either a wrong number or something like a form), there is a possibility to get one or two points if some part of your explanation is reasonable.
. Merely listing them is not enough.