Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

ps7 Sol

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

6.042/18.

062J Mathematics for Computer Science October 14, 2008


Tom Leighton and Marten van Dijk

Problem Set 7 Solutions


Due: Monday, October 20

Problem 1. [15 points] Express


n
X
i2 xi
i=0

as a closed-form function of n.
Solution. We use the derivative method. Let us start with the following formula, derived
in lecture (for x 6= 1):

n
X
i x − (n + 1)xn+1 + nxn+2
ix =
i=0
(1 − x)2

Differentiating both sides:

n
−1
X (1 − (n + 1)2 xn + n(n + 2)xn+1 )(1 − x)2 − (x − (n + 1)xn+1 + nxn+2 )(2(1 − x)(−1))
x i2 xi =
i=0
(1 − x)4
(1 − (n + 1)2 xn + n(n + 2)xn+1 )(1 − x) + 2(x − (n + 1)xn+1 + nxn+2 )
=
(1 − x)3
1 − (n + 1)2 xn + n(n + 2)xn+1 − x + (n + 1)2 xn+1 − n(n + 2)xn+2
=
(1 − x)3
2x − 2(n + 1)xn+1 + 2nxn+2
+
(1 − x)3
1 + x − (n + 1)2 xn + (n(n + 2) + (n + 1)2 − 2(n + 1))xn+1 + (2n − n(n + 2))xn+2
=
(1 − x)3
1 + x − (n + 1)2 xn + (2n2 + 2n − 1)xn+1 − n2 xn+2
= .
(1 − x)3

Multiplying both sides by x, we get


n
X x(1 + x − (n + 1)2 xn + (2n2 + 2n − 1)xn+1 − n2 xn+2 )
i 2 xi = .
i=0
(1 − x)3


2 Problem Set 7

Problem 2. [20 points]

n
22k−1 ?
Q
(a) [5 pts] What is the product of the first n odd powers of two:
k=1

Solution. Pn Pn Pn 2
Πnk=1 22k−1 = 2 k=1 2k−1
= 22 k=1 k− k=1 1
= 2n(n+1)−n = 2n


(b) [5 pts] Find a closed expression for


n X
X m
3i+j
i=0 j=0

Solution.
n X
m n m
!
X X X
3i+j = 3i · 3j
i=0 j=0 i=0 j=0
m
! n
!
X X
j i
= 3 · 3
j=0 i=0
 m+1   n+1 
3 −1 3 −1
= ·
2 2

(c) [5 pts] Find a closed expression for


n X
X n
(i + j)
i=1 j=1

Solution.
n X
n n X
n
! n X
n
!
X X X
(i + j) = i + j
i=1 j=1 i=1 j=1 i=1 j=1
n
! n
!
X X n(n + 1)
= ni +
i=1 i=1
2
2
2n (n + 1)
=
2
2
= n (n + 1)


Problem Set 7 3

(d) [5 pts] Find a closed expression for


n Y
Y n
2i · 3j
i=1 j=1

Solution.
n Y
n n
! n
!
Y Y Y
2i · 3j = 2ni 3nj
i=1 j=1 i=1 j=1
Pn Pn
n i=1 i n j=1 j
=2 3
n2 (n+1)/2 2 (n+1)/2
=2 3n


Problem 3. [10 points]

(a) [6 pts] Use integration to find upper and lower bounds that differ by at most 0.1 for the
following sum. (You may need to add the first few terms explicitly and then use integrals to
bound the sum of the remaining terms.)

X 1
i=1
(2i + 1)2

Solution. Let’s first try standard bounds:


Z ∞ ∞ Z ∞
1 X 1 1
2
dx ≤ ≤ f (1) + dx
1 (2x + 1) i=1
(2i + 1)2 1 (2x + 1)2

Evaluating the integrals gives:


∞ ∞ ∞
1 X 1 1 1
− ≤ ≤ + −
2(2x + 1) 1 i=1
(2i + 1)2 32 2(2x + 1) 1

1 X 1 1 1
≤ ≤ +
6 i=1
(2i + 1)2 9 6
These bounds are too far apart, so let’s sum the first couple terms explicitly and bound
the rest with integrals.
Z ∞ ∞ Z ∞
1 1 X 1 1 1
+ dx ≤ ≤ + f (2) + dx
32 2 (2x + 1)2 i=1
(2i + 1) 2 32
2 (2x + 1) 2

Integration now gives:


 ∞  ∞  ∞ 
1 1 X 1 1 1 1
2
+ − ≤ ≤ + 2+ −
3 2(2x + 1)
2 i=1
(2i + 1)2 32 5 2(2x + 1) 2
4 Problem Set 7

1 1 X 1 1 1 1
2
+ ≤ ≤ + 2+
3 10 i=1
(2i + 1)2 32 5 10
Now we have bounds that differ by 1/52 = 0.04. 

(b) [4 pts] Assume n is an integer larger than 1. Which of the following inequalities, if any,
hold. You may find the graph helpful.

n
X Z n
1. ln(i + 1) ≤ ln(x + 2)dx
i=1 0

Xn Z n
2. ln(i + 1) ≤ ln 2 + ln(x + 1)dx
i=1 1

Solution. The 1st inequality holds. 

Problem 4. [15 points] There is a bug on the edge of a 1-meter rug. The bug wants to
cross to the other side of the rug. It crawls at 1 cm per second. However, at the end of
each second, a malicious first-grader named Mildred Anderson stretches the rug by 1 meter.
Assume that her action is instantaneous and the rug stretches uniformly. Thus, here’s what
happens in the first few seconds:

ˆ The bug walks 1 cm in the first second, so 99 cm remain ahead.

ˆ Mildred stretches the rug by 1 meter, which doubles its length. So now there are 2 cm
behind the bug and 198 cm ahead.

ˆ The bug walks another 1 cm in the next second, leaving 3 cm behind and 197 cm
ahead.

ˆ Then Mildred strikes, stretching the rug from 2 meters to 3 meters. So there are now
3 · (3/2) = 4.5 cm behind the bug and 197 · (3/2) = 295.5 cm ahead.
Problem Set 7 5

ˆ The bug walks another 1 cm in the third second, and so on.

Your job is to determine this poor bug’s fate.

(a) [5 pts] During second i, what fraction of the rug does the bug cross?
Solution. During second i, the length of the rug is 100i cm and the bug crosses 1 cm.
Therefore, the fraction that the bug crosses is 1/100i. 

(b) [5 pts] Over the first n seconds, what fraction of the rug does the bug cross altogether?
Express your answer in terms of the Harmonic number Hn .
Solution. The bug crosses 1/100 of the rug in the first second, 1/200 in the second, 1/300
in the third, and so forth. Thus, over the first n seconds, the fraction crossed by the bug
is: n
X 1
= Hn /100
k=1
100k
(This formula is valid only until the bug reaches the far side of the rug.) 

(c) [5 pts] Approximately how many seconds does the bug need to cross the entire rug?
Solution. The bug arrives at the far side when the fraction it has crossed reaches 1. This
occurs when n, the number of seconds elapsed, is sufficiently large that Hn /100 ≥ 1. Now
Hn is approximately ln n, so the bug arrives about when:
ln n
≥1
100
ln n ≥ 100
n ≥ e100 ≈ 1043 seconds

Problem 5. [20 points] For each of the following six pairs of functions f and g (parts (a)
through (f)), state which of these order-of-growth relations hold (more than one may hold,
or none may hold):

f = o(g) f = O(g) f = ω(g) f = Ω(g) f = Θ(g) f ∼g

(a) f (n) = log2 n g(n) = log10 n


(b) f (n) = 2n g(n) = 10n
(c) f (n) = 0 g(n) = 17
 πn   πn 
(d) f (n) = 1 + cos g(n) = 1 + sin
2 2
(e) f (n) = 1.0000000001n g(n) = n10000000000
6 Problem Set 7

Solution. ˆ f (n) = log2 n and g(n) = log10 n:



f (n)
lim = lim ln n/ ln 2
n→∞ g(n) n→∞ ln n/ ln 10

ln 10
=
ln 2
So f (n) = Ω(g(n)) and f (n) = O(g(n)) and f (n) = Θ(g(n)).

ˆ f (n) = 2n and g(n) = 10n :


n

f (n)
lim = lim 2
n→∞ g(n) n→∞ 10n

= lim (1/5)n
n→∞
=0

So f (n) = o(g(n)) and f (n) = O(g(n)).

ˆ f (n) = 0 and g(n) = 17:



f (n)
lim
= 0
n→∞ g(n) 17
=0

So f (n) = o(g(n)) and f (n) = O(g(n)).

ˆ f (n) = 1 + cos πn πn
 
2
and g(n) = 1 + sin 2
:
For all n ≡ 1 (mod 4), f (n)/g(n) = 0, so f (n) 6= Ω(g(n)). Likewise, for all n ≡ 0
(mod 4), g(n)/f (n) = 0, so f (n) 6= O(g(n)). The quotient never converges to some
particular limit, so no relation holds.

ˆ f (n) = 1.0000000001n and g(n) = n10000000000 :


n

f (n)
lim = lim 1.0000000001
n→∞ g(n) n→∞ n10000000000
1.0000000001n ln 1.0000000001
= lim
n→∞ 10000000000n9999999999
1.0000000001n (ln 1.0000000001)10000000000
= lim
n→∞ 10000000000!
=∞

So f (n) = ω(g(n)) and f (n) = Ω(g(n)).



Problem 6. [15 points] This problem continues the study of the asymptotics of factori-
als.
Problem Set 7 7

(a) [5 pts]
Either prove or disprove each of the following statements.

ˆ n! = O((n + 1)!)
ˆ n! = Ω((n + 1)!)
ˆ n! = Θ((n + 1)!)
ˆ n! = ω((n + 1)!)
ˆ n! = o((n + 1)!)

Solution. Observe that n! = (n + 1)!/(n + 1), and thus n! = o((n + 1)!). Thus, n! =
O((n + 1)!) as well, but the remaining statements are false. 
 
n n+e

(b) [5 pts] Show that n! = ω 3
.

Solution. By Stirling’s formula:


√  n n
n! ∼ 2πn
e

n n+e
e n n
= n3

On the other hand, note that 3 3
. Dividing n! by this quantity,
√  n
3e 2π 3
e−1/2
· ,
n e
n+e
we see that since 3 > e, this expression goes to ∞. Thus, n! = ω n3 . 

(c) [5 pts] Show that n! = Ω(2n )


Solution. We can proceed straight from the definition. Recall n! is Ω (2n ) if and only if

n!
lim>0
n→∞ 2n

By multiplying and dividing by the same factor, we get


 n n √
n! n! 2πn
lim n = lim  n n √ e
n→∞ 2 n→∞
2πn 2n
e
And using Stirling’s approximation, we know the left part tends to 1. So we only need to
worry about
 n n √
2πn
lim e
n→∞ 2n
8 Problem Set 7

The expression in the limit can be manipulated to be


 n n √
2πn
2e
Since nn is strictly larger than 10n for n > 10, then

 n n √ n


10
lim 2πn > lim 2πn = ∞
n→∞ 2e n→∞ 2e

So the original limit must also be ∞. This also shows that in fact n! = ω (2n ) And the
same argument can be used to show that n! = ω (10n ) or any other constant base.


You might also like