Fundamental Algorithms, Assignment 4 Solutions
Fundamental Algorithms, Assignment 4 Solutions
Fundamental Algorithms, Assignment 4 Solutions
Solutions
1. Consider the recursion T (n) = 9T (n/3) + n2 with initial value T (1) =
1. Calculate the precise values of T (3), T (9), T (27), T (81), T (243).
Make a good (and correct) guess as to the general formula for T (3i )
and write this as T (n). (Dont worry about when n is not a power
of three.) Now use the Master Theorem to give, in Thetaland, the
asymptotics of T (n). Check that the two answers are consistent.
Solution:T (3) = 9(1) + 33 = 18 = 2(9), T (9) = 9(18) + 92 = 243 =
3(81), T (27) = 9(243) + 729 = 2916 = 4(729), T (81) = 32805 =
5(6561), T (243) = 354294 = 6(59049). In general, T (3i ) = (i + 1)32i .
With n = 3i we have 32i = n2 and i = log3 n so the formula is
T (n) = n2 (1 + log3 n). In Thetaland, T (n) = (n2 lg n). With the
Master Theorem, as log3 9 = 2 we are in the special case which gives
indeed T (n) = (n2 lg n).
Another approach is via the auxilliary function S(n) discussed in class.
Here S(n) = T (n)/n2 . Dividing the original recursion by n2 gives
T (n) T (n/3)
2
= +1
n (n/3)2
so that
so that
ln 5
log3 5 = = 1.46 < 1.58 = log2 3
ln 3
it is better that the (nlog2 3 ) of Karatsuba. (In practice unless n is
really large Karatsuba does better because Toom-3 has large constant
factors.)
4. Write the following sums in the form (g(n)) with g(n) one of the
standard functions. In each case give reasonable (they neednt be
optimal) positive c1 , c2 so that the sum is between c1 g(n) and c2 g(n)
for n large.