Algorithms Homework – Fall 2000 2.1-1 Let f(n) and g(n) be asymptotically nonnegative functions. Using the basic definition of notation, prove that max(f(n), g(n)) = ( f(n) + g(n)). Show: 0 c1(f(n) + g(n)) max(f(n), g(n)) c2(f(n) + g(n)) max(f(n), g(n)) c2(f(n) + g(n)), since f(n) and g(n) are asymptotically non-negative. Therefore, c2 = 1 and n0 = 1 max(f(n), g(n)) ½ (f(n) + g(n)), since the maximum value of ½ (f(n) + g(n)) = max(f(n), g(n)) Therefore, c1 = ½ 2.1-2 Show that for any real constants a and b, where b > 0, (n + a)b = (nb) Note: (a ch b) means “a choose b” for integers a and b (n + a)b = nb + (b ch 1)nb–1a + (b ch 2)nb–2a2 + … + ab So nb is the leading term in the polynomial. By the Sum Rule (proven in Exercise 2.1-1) the leading term sets the value. Therefore, (n + a)b = (nb) 2.2-1 Show that if f(n) and g(n) are monotonically increasing functions, then so are the functions f(n) + g(n) and f(g(n)), and if f(n) and g(n) are in addition nonnegative, then f(n) * g(n) is monotonically increasing. If two monotonically increasing functions are added together, the sum must also be monotonically increasing since there is nothing in the sum that decreases either of them. Since g(n) is monotonically increasing, once it is evaluated at any given point and a value is produced and this value is fed into another monotonically increasing function, f(n), the result must be monotonically increasing by the definition of a monotonically increasing function. If the results of two functions are the same sign, then the product of these results will be positive. Since both f(n) and g(n) are non-negative and monotonically increasing, the product of these two must also be monotonically increasing because there is nothing to decrease them. PROBLEMS 2-1 Asymptotic behavior of polynomials Let p(n) = di=0 aini where ad 0, be a degree-d polynomial in n, and let k be a constant. Use the definitions of the asymptotic notations to prove the following properties. a) If k d, then p(n) = O(nk). p(n) = a1nd + a2nd-1 + … Since k d, k – d 0 Therefore, nk grows as fast or faster than nd Therefore, p(n) = O(nk) Alternatively: p(n) d(adnd), for some large n Therefore, by setting c = d d(adnd) = O(nd) Therefore, since k d d(adnd) = O(nk) Therefore, since p(n) d(adnd) p(n) = O(nk) d) If k d, then p(n) = o(nk). Let f(n) = d(adnd) p(n) limn f(n)/nk = limn d(adnd)/nk = limn d(adnd-k) = limn dad/nk-d = 0 Therefore, p(n) = o(nk) 2-4 Asymptotic notation properties Let f(n) and g(n) be asymptotically positive functions. Prove of disprove each of the following conjectures. a) f(n) = O(g(n)) implies g(n) = O(f(n)). FALSE. Let f(n) = n2 and g(n) = n3 Then, f(n) = O(g(n)), but g(n) O(f(n)) b) f(n) + g(n) = (min(f(n), g(n))). FALSE. Let f(n) = n2 and g(n) = n3 Then min(f(n), g(n)) = n2 If f(n) + g(n) = n2 + n3 = ( n2) = (min(f(n), g(n))), then c1 and c2 0 and n0 0 such that 0 c1n2 n2 + n3 c2n2, for all n n0 But, 1 + n c2, for sufficiently large n So, this is a contradiction. c) f(n) = O(g(n)) implies lg(f(n)) = O(lg(g(n))), where lg(g(n)) 0 and f(n) 1 for all sufficiently large n. TRUE. Given: f(n) cg(n) Show: lg(f(n)) clg(g(n)) lg(f(n)) clg(g(n)) = lg(f(n)) lg(g(n))c Since we are given that lg(g(n)) 0, then c must be positive. Therefore, lg(g(n))c must grow faster than lg(f(n)) as n goes to , and is therefore an asymptotic upper bound. d) f(n) = O(g(n)) implies 2f(n) = O(2g(n)). FALSE. Let f(n) = n and g(n) = n/2, then f(n) = O(g(n)), with c 2 However, limn 2n/2/2n 1 Therefore, 2f(n) O(2g(n)) e) f(n) = O((f(n))2). FALSE. Let f(n) = 1/n2 Since, 1/n2 c(1/n2)2 = c/n4 for sufficiently large n, f(n) O((f(n))2) f) f(n) = O(g(n)) implies g(n) = (f(n)). TRUE. By transpose symmetry. f(n) = O(g(n)) implies g(n) = (f(n)) means that f(n) c(g(n)) implies g(n) c(f(n)) If, f(n) c(g(n)), then, 1/c f(n) g(n), which means that g(n) c(f(n)) g) f(n) = (f(n/2)). FALSE. f(n) = (f(n/2)) means that c1 and c2 0 and n0 0 such that 0 c1f(n/2) f(n) c2f(n/2), for all n n0 Let f(n) = 2n, then c1 and c2 0 and n0 0 such that 0 c12n/2 2n c22n/2, for all n n0 However, 2n grows faster than 2n/2 for sufficiently large n. Therefore, the constants c1 and c2 do not exist.