Sie sind auf Seite 1von 8

CS 173 Homework 3 Solutions Spring 2008

CS 173: Discrete Mathematical Structures, Spring 2008


Homework 3 Solutions
1. Prove the following by induction on n.
(a) If n 0 is an integer, then
n

j=0
j2
j
= (n 1)2
n+1
+ 2.
Solution: The proof is by induction on n. Base case: if n = 0, then

0
j=0
j2
j
= 0 =
(0 1)2
0+1
+ 2, so the formula holds.
Inductive step: let n 1. We have that
n

j=0
j2
j
=
_
_
n1

j=0
j2
j
_
_
+ n2
n
= (n 2)2
n
+ 2 + n2
n
(inductive hypothesis)
= ((n 2) + n) 2
n
+ 2
= (2n 2)2
n
+ 2
= 2(n 1)2
n
+ 2
= (n 1)2
n+1
+ 2,
so the theorem holds for n also.
(b) If n 0 is an integer, then
n

i=0
i
2
=
n(n + 1)(2n + 1)
6
.
Solution: The proof is by induction on n. Base case: if n = 0, then

0
i=0
= 0 =
011
6
, so
the theorem holds.
Inductive step: let n 1. We have that
n

i=0
i
2
=
_
n1

i=0
i
2
_
+ n
2
=
(n 1)((n 1) + 1)(2(n 1) + 1)
6
+ n
2
(inductive hypothesis)
=
(n 1)n(2n 1)
6
+ n
2
=
(n 1)n(2n 1) + 6n
2
6
=
n((n 1)(2n 1) + 6n)
6
=
n
_
2n
2
3n + 1 + 6n
_
6
=
n
_
2n
2
+ 3n + 1
_
6
=
n(n + 1)(2n + 1)
6
,
so the theorem holds for n also.
1
CS 173 Homework 3 Solutions Spring 2008
Grading: 10 points total; 5 points per part. In each part, award 1 point for introducing the
proof as a proof by induction on n, 1 point for the base case, and 3 points for the inductive
step.
2. Let H
n
=

n
j=1
1/j be the nth harmonic number. Harmonic numbers are common through-
out discrete mathematics and computer science, particularly in the analysis of randomized
algorithms and approximation algorithms. It is useful to know that H
n
ln n; in fact,
ln n H
n
ln n + 1. In this exercise, we prove bounds on H
n
when n is a power of
two.
(a) Compute H
4
(without a calculator).
Solution: By denition, H
4
=

4
j=1
1/j = 1 + 1/2 + 1/3 + 1/4 =
25
12
.
(b) Prove that k/2 + 1 H
2
k k + 1 for each k 0.
2
CS 173 Homework 3 Solutions Spring 2008
Solution: The proof is by induction on k. Base case: if k = 0, then H
2
0 = H
1
= 1.
Because 0/2 + 1 1 0 + 1, the inequalities are satised.
Inductive step: let k 1. The idea here is to split the sum H
2
k up into two sums,
apply the inductive hypothesis to one of the sums, and directly bound the terms in the
other sum. By denition of H
2
k, we have
H
2
k =
2
k

j=1
1
j
=
_
_
2
k1

j=1
1
j
_
_
+
_
_
2
k

j=2
k1
+1
1
j
_
_
= H
2
k1 +
_
_
2
k

j=2
k1
+1
1
j
_
_
Consider the sum

2
k
j=2
k1
+1
1
j
. This sum has 2
k1
terms, the largest term in the sum
occurs when j is smallest, and the smallest term in the sum occurs when j is largest.
Therefore each term in the sum is at most 1/(2
k1
+ 1) and each term in the sum is at
least 1/2
k
. It follows that
2
k

j=2
k1
+1
1
j

2
k

j=2
k1
+1
1
2
k1
+ 1
= 2
k1

1
2
k1
+ 1
< 1,
and similarly, we have that
2
k

j=2
k1
+1
1
j

2
k

j=2
k1
+1
1
2
k
= 2
k1

1
2
k
=
1
2
.
By the inductive hypothesis, (k 1)/2 + 1 H
2
k1 (k 1) + 1. For the upper bound,
we compute
H
2
k = H
2
k1 +
_
_
2
k

j=2
k1
+1
1
j
_
_
((k 1) + 1) + 1
= k + 1.
3
CS 173 Homework 3 Solutions Spring 2008
Similarly, for the lower bound, we compute
H
2
k = H
2
k1 +
_
_
2
k

j=2
k1
+1
1
j
_
_

_
k 1
2
+ 1
_
1
2
=
k
2
+ 1.
It follows that k/2 + 1 H
2
k k + 1, so the theorem holds in this case also.
Grading: 10 points total; 2 points part (a), 8 points part (b). In part (a), an answer with a
minor arithmetic error may earn 1 point. Answers that indicate confusion about

notation
earn 0 points.
Part (b), inductive proofs: award 1 point for introducing the proof as a proof by induction
and award 1 point for the base case. 6 points for the inductive step.
Part (b), other proofs: score out of 8 points.
3. Recall that the Fibonacci numbers are dened by the recurrence F
0
= 0, F
1
= 1, and F
n
=
F
n1
+F
n2
. Prove that every integer n 0 can be expressed as the sum of distinct Fibonacci
numbers without using any two consecutive Fibonacci numbers.
For example, 29 = F
6
+F
8
= 8 +21. (Note that 29 = F
4
+F
5
+F
8
= 3 +5 +21 expresses
29 as the sum of distinct Fibonacci numbers, but this sum uses the two consecutive Fibonacci
numbers F
4
and F
5
.)
Solution: The proof is by induction on n. Base case: if n = 0, then n = F
0
expresses 0 as the
sum of distinct Fibonacci numbers without using any two consecutive Fibonacci numbers.
Inductive step: let n 1. Our idea is to use a greedy approach and start with as large a
Fibonacci number as we possibly can. Let F
k
be the largest Fibonacci number that is at most
n so that F
k
n but F
k+1
> n. Let x = n F
k
be whatever is left after we remove F
k
from
n. Because n 1, certainly F
k
1 and so 0 x < n.
The inductive hypothesis implies that x can be expressed as the sum of distinct Fibonacci
numbers without using any two consecutive Fibonacci numbers. Adding F
k
to the sum for x
expresses n = x + F
k
as the sum of Fibonacci numbers. Moreover, we claim that the terms of
this sum are distinct Fibonacci numbers, no two of which are consecutive.
To prove our claim, we will argue in a moment that x < F
k1
. Because x < F
k1
, the sum
for x can use only the Fibonacci numbers in the set {F
0
, F
1
, . . . , F
k2
}. Therefore appending
F
k
to the sum cannot possibly introduce a repeated Fibonacci number or a consecutive pair.
Let us prove that x < F
k1
by contradiction. If it were the case that x F
k1
, then we
would have n = x + F
k
F
k1
+ F
k
= F
k+1
. But this is a contradiction, because we chose
F
k
so that F
k+1
> n. The contradiction implies that x < F
k1
and our proof is complete.
4
CS 173 Homework 3 Solutions Spring 2008
Grading: 10 points total. Several proofs are possible. For inductive proofs, award 1 point to
the introduction, another to the base case, the remaining 8 go to the inductive step. The idea
of using the largest Fibonacci number that is at most n is worth half credit.
4. Recently, a pirate ship with 200 pirates onboard has captured 1000 gold coins from another
vessel. The pirates have developed an interesting way to distribute their gains among them-
selves. Heres what happens: the strongest pirate on the ship proposes a distribution of the
coins to pirates. Next, all pirates vote on the proposal (including the strongest pirate). If at
least half of the pirates vote in support of the proposal, the coins are distributed according to
the proposal and the process is complete. However, if more than half of the pirates vote to
reject the proposal, they throw the strongest pirate overboard and the process repeats with
the strongest of the remaining pirates offering a new proposal. Each pirate is perfectly logical
and wishes to maximize the number of coins that he or she receives.
You are the strongest pirate. What is the maximum number of gold coins you can keep
for yourself? Prove that your answer is correct. (Hint: there is exactly one correct answer.)
Solution: This solution uses oor and ceiling notation. The oor of a real number x, written
x, is the largest integer k such that k x. Similarly, the ceiling of a real number x, written
x, is the smallest integer k such that k x.
Suppose there are n pirates p
1
, p
2
, . . . , p
n
onboard, ordered from strongest pirate p
1
to
weakest pirate p
n
. We claim that p
1
proposes the following distribution: p
2
, p
4
, p
6
, . . . each
receive 0 gold coins, p
3
, p
5
, p
7
, . . . each receive 1 gold coin, and p
1
gets the remaining 1000
_
n1
2
_
gold coins.
We prove the claim by induction on n. Base case: if n = 1, then p
1
proposes to receive all
gold coins, which is consistent with our claim.
Inductive step: let n 2. Because p
1
is perfectly logical and wishes to maximize the number
of gold coins p
1
receives, p
1
will reason as follows: I need at least n/2 of my fellow pirates to
vote in favor of my proposed distribution. If my proposal is rejected and I am thrown off the
ship, p
2
will offer a new distribution. By the inductive hypothesis, I know that p
2
will offer
zero gold coins to p
3
, p
5
, p
7
, . . ., one gold coin to p
4
, p
6
, p
8
, . . ., and keep the rest. Furthermore,
all my fellow pirates are perfectly logical and know full well how the coins will be distributed
if Im thrown overboard. I can only be sure that a pirate p
j
will vote for my proposal if I offer
p
j
more than p
j
would get if p
2
were running the show. Because I want to get as many coins
as possible, I should start by offering gold coins to the pirates that receive the fewest number
of gold coins under p
2
s distribution, and I should continue buying off votes until I am sure
that at least n/2 pirates will vote for me. So, I will offer one coin to each of p
3
, p
5
, p
7
, . . . and
keep the rest. That way, I will get votes from p
1
, p
3
, p
5
, . . ., so I will get
_
n
2
_
n/2 votes and
my proposal will be accepted. Unfortunately, I cant do any better because I need at least
_
n
2
_
votes and Ive bought each for the cheapest possible price. Therefore p
1
makes the claimed
proposal, and our proof is complete.
In our case with n = 200, the strongest pirate p
1
offers zero gold coins to p
2
, p
4
, . . . , p
200
,
one gold coin to p
3
, p
5
, p
7
, . . . , p
199
and keeps the remaining 901 coins.

5
CS 173 Homework 3 Solutions Spring 2008
Grading: 10 points total; 2 points for answering the question (901 coins) correctly, and 8
points for the proof of correctness. Deduct 2 points from solutions that only argue that the
proposed distribution will be accepted and forget to argue that the proposed distribution is
the best possible for the strongest pirate.
5. Let k 0 be an integer and let n = 2
k
. Suppose you are given a square which is divided
into n
2
smaller squares. The small squares are all colored blue, except that one special square
is colored red. You are also given access to green game pieces which can be placed on the
board. Each game piece comes in an L shape and covers three of the smaller squares. Show
that you can place the game pieces on the board in such a way that the pieces do not overlap
and cover all the blue squares, leaving the red square uncovered. An example with n = 8
appears below.
Solution: The proof is by induction on k. Base case: if k = 0, the game consists of a single
square, much must be colored red, and the requirements are satised by not placing any
game pieces on the board.
Inductive step: if k 1, we partition the board into its 4 quadrants, each of which is a
smaller 2
k1
2
k1
board. Note that the red square is located in just one of the quadrants;
the other three are lled with blue squares. By rotating the original board, we might as well
assume that the red square is located in the upper-right quadrant, as in the example above.
Next, we color 3 more squares red: the lower-right corner of the upper-left quadrant,
the upper-right corner of the lower-left quadrant, and the upper-left corner of the lower-
right quadrant. Note that these three squares form an L shape, and each of the quadrants
contains exactly one red square. By the inductive hypothesis, we may cover each of the
smaller quadrants with green game pieces, leaving only the 4 red squares uncovered. Finally,
we place a game piece on the 3 squares we colored red. Except for the original red square,
all squares are covered with green game pieces and we are done.
Grading: 10 points. Award 1 point for the introduction and 1 point for the base case. The re-
maining 8 go to the inductive step. The idea of splitting up the board into quadrants is worth
3 of these 8 points. The idea of adding new red squares to the quadrants that are missing red
squares is worth another 2 points.
6
CS 173 Homework 3 Solutions Spring 2008
6. [Honors] Let n 3 be an odd integer. An art museum has n rooms arranged in a circle.
Each room is equipped with an overhead light and a light switch. When a switch is ipped,
it toggles the overhead lights in the two adjacent rooms; the on/off status of the other lights
(including the light in the switchs room) is unchanged.
(a) From which initial congurations is it possible to turn off all the overhead lights in
the museum? Your answer must describe a specic condition (for example, no three
consecutive rooms have overhead lights turned on).
Solution: All lights can be turned off if and only if an even number of lights are turned
on.
(b) Prove that if the initial conguration meets your condition, it is possible to turn off all
the lights.
Solution: First, we prove a lemma which will also be useful in part (c).
Lemma. Flipping a switch preserves the parity of the number of lights turned on. That
is, if we start with a conguration with an even number of lights turned on, then after
ipping a switch, there are still an even number of lights turned on. Similarly, if we
start with a conguration with an odd number of lights turned on, then after ipping a
switch, there are still an odd number of lights turned on.
Proof: Suppose that there are k lights turned on, let x, y, and z be three consecutive
rooms in the art museum and consider what happens if we ip the switch in room y. If
the lights in x and z are both off, we will end up in a conguration with k + 2 lights on.
If the lights in x and z are both on, we will end up in a conguration with k 2 lights
on. If one light is on and the other is off, we will end up in a conguration with k lights
on. Because k 2, k, and k + 2 all have the same parity, the parity of the number of
lights turned on stays the same.
This lemma argues that the parity of the number of lights turned on cannot change,
no matter how we ip light switches. In other words, the parity of the number of lights
turned on is invariant under ipping a single switch. It follows by induction that the
parity of the number of lights turned on is invariant under ipping switches arbitrarily
many times. Invariant arguments such as this one are quite common.
We prove that if an even number of lights are turned on, then we can turn off all the
lights. The proof is by induction on n. Base case: if n = 3 and an even number of lights
are turned on, then either zero lights are on or two lights are on. If zero lights are on,
we are done. If two lights are on, ipping the switch in the room with the light turned
off turns off all lights and we are done.
Inductive step: let n 5 be odd and consider a conguration where an even number
of lights are on. We show that we can turn all the lights off. Let w, x, y, and z be four
consecutive rooms in the art museum. By ipping the switches in rooms w and z as
necessary, we can reach a conguration where the lights in x and y are turned off. By
the lemma, there are still an even number of lights turned on.
Next, we would like to throw away the rooms x and y, and use the inductive hy-
pothesis to turn off the lights in the remaining n2 rooms. The problem is that ipping
the switch in room w changes the light in room x, whereas we would like it to change
the light in room z.
7
CS 173 Homework 3 Solutions Spring 2008
Even though we cannot really throw away the rooms x and y, we can do the next best
thing: we can simulate an art museum where w and z are adjacent and where x and
y are removed. Heres how: whenever we ip the switch in room w, we immediately
ip the switch in room y. Note that ipping the switches in both w and y cancels the
effect on room x, and ipping the switch in y changes the light in room z. Similarly,
whenever we ip the switch in room z, we immediately ip the switch in room x. Note
that between light switch ips in the simulated museum, the lights in rooms x and y stay
off.
Note that our simulated art museum has n2 rooms, and has an even number of lights
turned on (because the lights in x and y are both off). By the inductive hypothesis, it
is possible to turn off all the lights in our simulated museum. Because lights in x and y
stay off between light switch ips in the simulated museum, all lights in the original art
museum are turned off as well.
(c) Prove that if the initial conguration fails to meet your condition, it is not possible to
turn off all the lights.
Solution: Suppose that an odd number of lights are turned on. By the lemma in part
(b), no matter how the switches are ipped, we will always be in a conguration with
an odd number of lights turned on. It follows that we can never reach the conguration
where zero lights are turned on.
(For a challenge, try to solve the museum problem when n is even.)
Grading: 12 points total. Part (a): 3 points. Part (b): 6 points. Part (c): 3 points.
8

Das könnte Ihnen auch gefallen