You are on page 1of 1

Solution to Homework 2

HW2.1
(a) Taking logarithms on both functions, we get (log n)2 and n log log n. Since polynomials are
faster than polylogarithms, n log log n is faster. Thus, (log n)n is faster.
(b) Taking logarithms on both functions and using Sterlings approximation, we get n! log n!
and (n 1)! log(n 1)! + n! log(n 1)!. By simple math, we see that n! log n! > (n 1)! log(n 1)! +
n! log(n 1)!. Using that f (n) = (g(n)) iff log f (n) > log g(n), we conclude that (n!)! is faster.
HW2.2
(a) O, o (Polynomials grow faster than polylogarithms);
(b) No relation (nsin n is a periodical function);
(c) O, , (Sterlings approximation);
(d) , (4n = 2n 2 n );

1
(e) O, o (Consider log n log n and log 2 2 log n ).
HW2.3
(a) Using the recursion tree method, T (n) = O(n log n).
(b) Using iteration method, (Cannot use master theorem, why?) assume n = 2k and T (1) = 1.
T (n) =
=
=
=
=
=
=

2T (n/2) + n/ log n
22 T (n/22 ) + n(1/ log(n/2) + 1/ log n)

2k T (n/2k ) + n(1/ log(n/2k1 ) + + 1/ log(n/2) + 1/ log n)


n + n(1/1 + 1/2 + 1/3 + + 1/k)
n + n(ln k + O(1))
O(n log log n)

(c) Using the master theorem, let a = b = 2 and f (n) = n. Case 1 holds. So T (n) = (n).
HW2.4
R0 = 1 and Rn = Rn1 + n. Therefore, Rn = 12 n(n + 1) + 1. If the nth line intersects the
previous lines in k > 0 distinct points, we get k 1 new bounded regions and 2 new infinite regions.
Hence, Bn = (n 2) + (n 3) + + 1 = 21 (n 1)(n 2) = Rn 2n.

You might also like