Homework 1 Solutions 50 points Define a function f to be admissable iff it is defined on almost all of the nonnegative integers and has non-negative real values on almost all of the domain. That is, there is an integer n0 such that f (n) is defined and f (n) ≥ 0 for all integers n > n0 . Note that for polynomials, this condition requires that the leading coefficient is a positive number. Proposition 1. If f and g are admissable and f ≤ O(g) then Θ(f + g) = Θ(g). Proof. Applying the definition of big-O, we find that there is a positive constant C and a positive integer n1 such that f (n) ≤ Cg(n) for n ≥ n1 . Therefore we have f (n) + g(n) ≤ Cg(n) + g(n) = (C + 1)g(n) for n ≥ n1 . Taking C1 = 1 + C we have f (n) + g(n) ≤ C1 g(n) and thus f + g ≤ O(g). On the other hand, note that by admissibility there exists a positive integer n2 such that f (n) ≥ 0 and therefore g(n) ≤ f (n) + g(n) for all n ≥ n2 . Taking C2 = 1, we then have C2 g(n) ≤ f (n) + g(n) for all n ≥ n2 and thus f + g ≥ Ω(g). It now follows that f + g = Θ(g). Exercise. Prove or disprove: Θ(1 + g) = Θ(g) for any admissable g. Solution. This statement is false. Reading Prop 1 above, we see that a counterexample must satisfy g = o(1), that is, g(n) → 0 as n → ∞. Any such g will do - for example, g(n) = 1/n. There is no C > 0 such that g(n) ≥ C for almost all n. 1 2 Proposition 2. Suppose that f and g are admissable and f (n) lim =C n→∞ g(n) where C is a non-negative constant. Then f = O(g) and g = Ω(f ). Moreover, if C > 0 then f = Θ(g). Proof. By the definition of limit, f (n)/g(n) → C, with = 1, there exists a positive integer n1 such that f (n)/g(n) ≤ C + 1 for n ≥ n1 . Taking C1 = 1 + C we have f (n)/g(n) ≤ C1 and after algebra f (n) ≤ C1 g(n) for n ≥ n1 . Therefore f ≤ O(g). If in addition C > 0, again applying the definition of limit with = C/2, there is a positive integer n2 such that f (n)/g(n) ≥ C/2 for n ≥ n2 . Taking C2 = C/2 we have f (n)/g(n) ≥ C2 and after algebra C2 g(n) ≤ f (n) for n ≥ n2 . Therefore f ≥ Ω(g). Proposition 3. If a and b are positive numbers (not necessarily integers) and a ≤ b then na ≤ O(nb ) and nb ≥ Ω(na ). Proof. Let f (n) = na and g(n) = nb , and consider the quotient: f (n) na = b = na−b . g(n) n Note that c = a − b ≤ 0 implies that nc → 0 as n → ∞. Applying Prop 2 above, we conclude that f ≤ O(g). 3 Proposition 4. Suppose p is a polynomial in n of degree d, with the form p(n) = d X ai ni i=0 with leading coefficient ad > 0. Then p(n) = Θ(nd ). Proof 1. Note that p(n) = q(n) + ad nd where q(n) = d−1 X ai ni i=0 If ad−1 < 0 then q is not admissible and moreover q(n) < 0 for almost all n. Otherwise q ≤ O(ad nd ) by Prop 3. Therefore, by Prop 1 with g(n) = ad nd , we have p = Θ(ad nd ) = Θ(nd ). Proof 2. Consider the quotient d p(n) X ai ni−d = d n i=0 Note that all of the terms on the right have negative exponent except for the last one ad nd−d = ad which is a positive constant. Therefore p(n) lim = ad n→∞ nd Since ad > 0, Prop 2 concludes that p = Θ(nd ).