Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
0 of .
Results for:
P. 1
Classes.soe.Ucsc.edu Cmps102 Fall01 Solutions 2

Classes.soe.Ucsc.edu Cmps102 Fall01 Solutions 2

Ratings: (0)|Views: 1|Likes:

Availability:

See more
See less

04/23/2012

pdf

text

original

CS 102: INTRO. TO THE ANALYSIS OF ALGORITHMSASSIGNMENT 2SOLUTIONSProblem 1.
ni
=1
i
2
=
n
(
n
+1)(2
n
+1)6
for
n
1.
Solution.
The proof will be by induction on
n
. The base case is
n
= 1. Theleft-hand side of the equation becomes
1
i
=1
i
2
= 1 and the right-hand side is
1(1+1)(2+1)6
=
2
×
36
= 1. Thus the base case holds.Now assume that the above equation hold for
n
=
k
1 where
k
N
is someconstant such that
k
1
1. Thus in,
k
i
=1
i
2
=
k
1
i
=1
i
2
+
k
2
we can replace the second summaion and get,
k
i
=1
i
2
=(
k
1)(
k
1 + 1)[2(
k
1) + 1]6+
k
2
=
k
(
k
1)(2
k
1)6+6
k
2
6=
k
[(
k
1)(2
k
1) + 6
k
]6=
k
(2
k
2
3
k
+ 1 + 6
k
)6=
k
(2
k
2
+ 3
k
+ 1)6=
k
(
k
+ 1)(2
k
+ 1)6.Thus the equation holds for some
k
given that it holds
k
1. By induction it followsthat the equation holds for all
n
N
.
Problem 2.
ni
=0
x
i
=
x
n
+1
1
x
1
for
x
= 1 and
n
0.
Solution.
The proof is by induction on
n
. The base case is
n
= 0. We prove it thus,
0
i
=0
x
i
=
x
0
= 1 =
x
1
1
x
1.Now, assume that the equation is true for some
k
N
and
n
=
k
1
0.Consider,
k
i
=0
x
i
=
k
1
i
=0
x
i
+
x
k
=
x
k
1
x
1+
x
k
Where the second equality comes from applying the induction hypothesis. Contin-uing,
k
i
=0
x
i
=
x
k
1
x
1+(
x
1)
x
k
x
1=
x
k
1 +
x
k
+1
x
k
x
1=
x
k
+1
1
x
1.Which is the desired result for
n
=
k
. By induction, the equation is true for all
n
N
.
1

CS 102: INTRO. TO THE ANALYSIS OF ALGORITHMS ASSIGNMENT 2 SOLUTIONS 2
Problem 3.
Consider the following statement: the sum of cubes of the ﬁrst
n
positive integers is equal to the square of the sum of these integers. Restate this asa formal mathematical theorem using Σ-notation. Prove your theorem.
Solution.
Theorem 1.
For
n
N
and
n
1
,
n
i
=1
i
3
=
n
i
=1
i
2
.Proof.
The proof is by induction on
n
. The base case is when
n
= 1,
1
i
=1
i
3
= 1 =
1
i
=1
i
2
.Now assume that the theorem holds for
n
=
k
1 for some
k
N
,
k
1
1.Thus we get that,
k
i
=1
i
3
=
k
1
i
=1
i
3
+
k
3
=
k
1
i
=1
i
2
+
k
3
Where the last equation comes from applying the induction hypothesis. Now weuse the fact that
k
1
i
=1
i
=
k
(
k
1)
/
2 to show that,
k
i
=1
i
3
=
k
(
k
1)2
2
+
k
3
=
k
2
(
k
2
2
k
+ 1)4+4
k
3
4=
k
2
(
k
2
+ 2
k
+ 1)4=
k
2
(
k
+ 1)
2
4=
k
(
k
+ 1)2
2
.Which is the equation with
n
=
k
. Therefore, by induction, the theorem holds.
Problem 4.
n
5
n
is divisible by 5 for every positive integer
n
.
Solution.
The proof will follow by induction on the
n
. We prove the base case,
n
= 1, follows because
n
5
n
= 1
5
1 = 0 is divisible by 5.Now we assume that
k
5
k
is divisible by 5 for some positive integer
k
. Consider,(
k
+ 1)
5
(
k
+ 1) =
k
5
+ 5
k
4
+ 10
k
3
+ 10
k
2
+ 5
k
+ 1
k
1= (
k
5
k
) + 5(
k
4
+ 2
k
3
+ 2
k
2
+
k
)The ﬁrst term is divisible by 5 because of the induction hypothesis and the secondterm is divisible by 5 because is contains a factor of 5. Thus the sum is divisibleby 5. This proves the induction hypothesis and completes the proof.
Problem 5.
Find (and prove) an exact closed form solution to
(
n
) mapping thenatural numbers to the reals deﬁned by
(
n
) =
n
if
n
= 0 or
n
= 1,5
(
n
1) + 6
(
n
2) otherwise.

CS 102: INTRO. TO THE ANALYSIS OF ALGORITHMS ASSIGNMENT 2 SOLUTIONS 3
Solution.
Claim:
(
n
) =
17
6
n
17
(
1)
n
.
The proof is by induction on
n
.
Base:
(note that there are
two
base cases since the recurrence uses two previousvalues
(
n
1) and
(
n
2)).n=0 :
(0) =
6
0
7
(
1)
0
7
=
17
17
= 0, and we have
(0) = 0 by the recursivedeﬁnition of
.n=1 :
(1) =
6
1
7
(
1)
1
7
=
67
+
17
= 1, and we have
(1) = 1 by the recursivedeﬁnition of
.
Inductive Step:
Assume
n >
1. Assume
(
j
) =
17
6
j
17
(
1)
j
, for all
j
suchthat 0
j < n
. Let IH(
j
) be the statement
(
j
) =
6
j
7
(
1)
j
7
, so we are assumingIH(
j
) for 0
j < n
. We need to show that
(
n
) = 6
n
/
7
(
1)
n
/
7.Since
n >
1, we can use the recursive deﬁnition of
to get that
(
n
) = 5
(
n
1) + 6
(
n
2).We can use IH(
n
1) and IH(
n
2) to rewrite
(
n
1) and
(
n
2). So from theinductive hypothesis we get:
(
n
) = 5
6
n
1
7
(
1)
n
1
7
+ 6
6
n
2
7
(
1)
n
2
7
=5
×
6
n
1
7+6
×
6
n
2
7
5
×
(
1)
n
1
7
6
×
(
1)
n
2
7=6
n
2
7[5(6) + 6]
(
1)
n
2
7[5(
1) + 6]=6
n
2
7(36)
(
1)
n
2
7(1)=6
n
2
7(6
2
)
(
1)
n
2
7(
1)
2
=17
×
6
n
17(
1)
n
which is what we needed to show.
Problem 6.
Deﬁne the following recurrence
(
n
) =
1 if
n
= 06 if
n
= 16
(
n
1) + 9
(
n
2) for all
n
2Show that
(
n
)
n
3
n
for all
n
0.
Solution.
Proof
by induction on
n
.
Note that there will need to be two base casesfor this induction proof. One (
n
= 0) is not suﬃcient because then our inductivestep would have to cover 1
,...,n
. This presents a problem because our recurrenceis not deﬁned for
n
= 1. In general when there are two recursive references to afunction like
, namely
(
n
1 and
(
n
2), two base cases are required for aproof by induction.
Base Step:
n
= 0: By deﬁnition
(0) = 1
(0)3
0
= 0.
n
= 1: again we have
(1) = 6
(1)3
1
= 3.