CSE 431/531: Analysis of Algorithms Spring 2016 Lecture 2: Asymptotic Notations Jan 27, 2016 Lecturer: Shi Li Fill the 5 spaces with one of the 5 comparison relations: <, ≤, >, ≥, =. f (n) = O(g(n)) f g f (n) = Ω(g(n)) f g f (n) = Θ(g(n)) f g f (n) = o(g(n)) f g f (n) = ω(g(n)) f g Definition 2.1 (O-Notation) For a function g(n), O(g(n)) = function f : ∃c > 0, n0 > 0 such that f (n) ≤ cg(n), ∀n ≥ n0 . Definition 2.2 (Ω-Notation) For a function g(n), Ω(g(n)) = function f : ∃c > 0, n0 > 0 such that f (n) ≥ cg(n), ∀n ≥ n0 . Definition 2.3 (Θ-Notation) For a function g(n), Θ(g(n)) = function f : ∃c2 ≥ c1 > 0, n0 > 0 such that c1 g(n) ≤ f (n) ≤ c2 g(n), ∀n ≥ n0 . Definition 2.4 (o-Notation) For a function g(n), o(g(n)) = function f : ∀c > 0, ∃n0 > 0 such that f (n) ≤ cg(n), ∀n ≥ n0 . Definition 2.5 (ω-Notation) For a function g(n), ω(g(n)) = function f : ∀c > 0, ∃n0 > 0 such that f (n) ≥ cg(n), ∀n ≥ n0 . Exercise 2.6 3n2 + 2n = O(n2 ). Proof: Let n0 = 2 and c = 4. Then, for every n ≥ n0 = 2, we have 3n2 + 2n ≤ 3n2 + n × n = 4n2 = cn2 . Thus, we have 3n2 + 2n = O(n2 ). Exercise 2.7 3n2 − 10n = Ω(n2 ). Proof: Let n0 = 5 and c = 1. Then, for every n ≥ n0 = 5, we have 3n2 − 10n = n2 + (2n − 10)n ≥ n2 = cn2 . Thus, we have 3n2 − 10n = Ω(n2 ). Exercise 2.8 3n2 + 5n + 10 = o(n2 lg n). 2-1 Lecture 2: Asymptotic Notations Proof: Let c > 0 be any real number. Define n0 = max{29/c , 2 + 15/c, 2 + every n ≥ n0 , we have 3 ≤ c lg n/3, 5 ≤ cn lg n/3 and 10 ≤ cn2 lg n/3. 2-2 p 30/c}. Then, for 3n2 + 5n + 10 ≤ cn2 lg n/3 + cn2 lg n/3 + cn2 lg n/3 = cn2 lg n. So, for every c > 0, there exists n0 > 0 such that for every n ≥ n0 , we have 3n2 + 5n + 10 ≤ cn2 lg n. Thus, 3n2 + 5n + 10 = o(n2 lg n). Theorem 2.9 f (n) = O(g(n)) if and only if g(n) = Ω(f (n)). Proof: We first prove the “only if” direction. Assume f (n) = O(g(n)). Then, by the definition of the O-notation, there are numbers c > 0, n0 > 0 such that for every n ≥ n0 we have f (n) ≤ cg(n). Define c0 = 1/c. Then, for every n ≥ n0 , we have g(n) ≥ c0 f (n). By the definition of the Ω-notation, we have g(n) = Ω(f (n)). Thus, f (n) = O(g(n)) implies g(n) = Ω(f (n)). The “only if” direction holds. The “if” direction can be proved in exactly the same way. Theorem 2.10 f (n) = Θ(g(n)) if and only if f (n) = O(g(n)) and f (n) = Ω(g(n)). Proof: We first prove that if f (n) = Θ(g(n)) then f (n) = O(g(n)) and f (n) = Ω(g(n)). By the definition of Θ-notation, we have that there exists three numbers c2 ≥ c1 > 0, n0 > 0 such that for every n ≥ n0 , we have c1 g(n) ≤ f (n) ≤ c2 g(n). So, for every n ≥ n0 , we have f (n) ≤ c2 g(n). Thus, f (n) = O(g(n)). Moreover, for every n ≥ n0 , we have f (n) ≥ c1 g(n), thus, f (n) = Ω(g(n)). We then prove that if f (n) = O(g(n)) and f (n) = Ω(g(n)), then f (n) = Θ(g(n)). By the definition of O-notation, there exists c > 0, n0 > 0 such that for every n ≥ n0 , we have f (n) ≤ cg(n). By the definition of Ω-notation, there exists c0 > 0, n00 > 0 such that for every n ≥ n00 , we have f (n) ≥ c0 g(n). Define n000 = max{n0 , n00 }. Then, for every n ≥ n000 , we have c0 g(n) ≤ f (n) ≤ cg(n). Thus, f (n) = Θ(g(n)).