Sei sulla pagina 1di 2

HW 3 Answers Ex. 4.2-3 Suppose n is not a power of 2. Let 2k1 < n < 2k .

We augment matrix A to a matrix A of dimension 2k 2k such that A [i, j] = A[i, j] if i n and j n, and A [i, i] = 1 if i > n and j > n, and A [i, j] = 0 otherwise. Similarly, we augment B to B . Then apply Strassens method to compute A B which takes time O((2k )lg 7 ) = O((2n)lg 7 ) = O(2lg 7 nlg 7 ) = O(nlg 7 ) since 2k = 2 2k1 2n. Next, the result of A B is easily retrieved from the result of A B as (A B)[i, j] = (A B )[i, j] for 1 i, j n. Ex. 4.3-9 k k Let T (n) = 3T ( n ) + lg n. First, let n = 22 where k 1. Then T (22 ) = k1 k2 k3 3T (22 ) + 2k = 32 T (22 ) + 3 2k1 + 2k = 33 T (22 ) + 32 2k2 + 3 2k1 + 0 2k = . . . = T (22 ) + k1 3i 2ki = (1) + 3k k (2/3)j = (1) + 3k (1) = j=1 i=0 k (3k ) Thus, T (n) = (3k ) = (3lg lg n ) = ((lg n)lg 3 ) for n = 22 . Hence, k there exists c1 , c2 , k0 such that for k k0 , c1 3k T (22 ) c2 3k . Since T (3) = 3T (2) + lg 3 and T (4) = 3T (2) + lg 4, we have T (2) T (3) T (4). Using the same technique as given in Note 10, we can show by induction that T (n) is monotonically increasing. In general, for any n > 2 there exists a k 1 such that 22 < n 22 ; k < 2 lg n. In addition, we consider n n = 22k0 +1 . equivalently, lg n 2 0 We have T (n) T (22 ) c2 3k = c2 (2lg 3 )k = c2 (2k )lg 3 c2 (2 lg n)lg 3 = c2 2lg 3 (lg n)lg 3 = c (lg n)lg 3 where c = c2 2lg 3 . Next, we have T (n) T (22 ) c1 3k1 = (c1 /3)3k = (c1 /3)(2lg 3 )k = (c1 /3)(2k )lg 3 (c1 /3)(lg n)lg 3 = c (lg n)lg 3 where c = c1 /3. Therefore, T (n) = ((lg n)lg 3 ). Problem 4-3 (b) Consider the values of T when n = 3k for k 1. By applying the recurrence i times, we get T (3k ) = 3i T (3ki ) + 3k 1 1 1 1 ( + + ... ) lg 3 k i + 1 k i k 1
k1 k k1 k

1 Thus, by taking i = k, we have T (3k ) = 3k T (1) + 3k lg 3 Hk where Hk is the k-th harmonic number. Thus, T (n) = T (3k ) = (3k Hk ) = (3k ln k) = (3k lg k ) = (3k lg k) = (n lg lg n). lg e

Problem 4-3 (f) It is clear that T (n) n. Thus, T (n) = (n). Suppose we guess that T (n) kn. If the guess is correct, then the induction proof should work. By the induction hypothesis, T (n/2) kn/2, T (n/4) kn/4 and T (n/8) kn/8. Therefore, T (n) = T (n/2)+T (n/4)+T (n/8)+n kn/2+kn/4+kn/8+n = ((7/8)k + 1)n which we want it to be less than or equal to kn. By solving (7/8)k + 1 k, we have k 8. We are done by selecting k = 8. Thus, T (n) = (n). A more careful proof will require the discussion of the base cases. Question 5 Base case: (when n=1.) By denition, T (1) = 1, while t(1) = 2(1 + 1)H1 3 1 = 2 2 3 = 1. Therefore T (1) = t(1). Assume that T (k) = t(k) for some k 1. 2 T (k + 1) = (k + 1) + k+1 k T (i) (by the def of T ) i=1 2 = (k + 1) + k+1 (T (k) + k1 T (i)) i=1 2 2 = (k + 1) + k+1 T (k) + k+1 ( k1 T (i)) i=1 2 1 = (k + 1) + k+1 T (k) + k+1 (2 k1 T (i)) i=1 2 1 = (k + 1) + k+1 T (k) + k+1 (kT (k) k 2 ) The last equality was because of the following reasons: By denition, T (k) = k + (2/k) k1 T (i). Using algebra, the above becomes k T (k) = k 2 + i=1 2 k1 T (i) which is equivalent to k T (k) k 2 = 2 k1 T (i). Continuing i=1 i=1 with the rewriting of T (k + 1) and applying the induction hypotheis that T (k) = t(k), we have 1 T (k + 1) = (k + 1) + k+2 T (k) k+1 k 2 k+1 1 k+2 = (k + 1) + k+1 t(k) k+1 k 2 k+2 1 = (k + 1) + k+1 (2(k + 1)Hk 3k) k+1 k 2 k+2 1 = (k + 1) + 2(k + 2)Hk k+1 3k k+1 k 2 1 Next, substituting Hk by Hk+1 k+1 and applying algebraic simplications, we obtain T (k + 1) = 2(k + 2)Hk+1 3(k + 1)

Potrebbero piacerti anche