Ymp 16 comp 122 o notation for a given function gn the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ⇒ Best case is Ω (f(n)) Can still say “Worst-case running time is Ω (f(n))” Means worst-case running time is given by some unspecified function g(n) ∈ Ω (f(n)). mp - 14 Comp 122 Example Insertion sort takes Θ(n2) in the worst case, so sorting (as a problem) is O(n2). Why? Any sort algorithm must look at each item, so sorting is Ω (n). In fact, using (e.g.) merge sort, sorting is Θ(n lg n) in the worst case. Later, we will prove that we cannot hope that any comparison sort to do better in the worst case. mp - 15 Comp 122 Asymptotic Notation in Equations Can use asymptotic notation in equations to replace expressions containing lower-order terms. For example, 4n3 + 3n2 + 2n + 1 = 4n3 + 3n2 + Θ(n) = 4n3 + Θ(n2) = Θ(n3). How to interpret? In equations, Θ(f(n)) always stands for an anonymous function g(n) ∈ Θ(f(n)) In the example above, Θ(n2) stands for 3n2 + 2n + 1. mp - 16 Comp 122 o-notation For a given function g(n), the set little-o: o(g(n)) = {f(n): ∀ c > 0, ∃ n0 > 0 such that ∀ n ≥ n0, we have 0 ≤ f(n) < cg(n)}. f(n) becomes insignificant relative to g(n) as n approaches infinity: lim [f(n) / g(n)] = 0 n→∞ g(n) is an upper bound for f(n) that is not asymptotically tight. Observe the difference in this definition from previous ones. Why? mp - 17 Comp 122 ω -notation For a given function g(n), the set little-omega: ω(g(n)) = {f(n): ∀ c > 0, ∃ n > 0 such that ∀ n ≥ n0, we have 0 ≤ cg(n) < f(n)}. 0 f(n) becomes arbitrarily large relative to g(n) as n approaches infinity: lim [f(n) / g(n)] = ∞ . n→∞ g(n) is a lower bound for f(n) that is not asymptotically tight. mp - 18 Comp 122 Comparison of Functions f↔g ≈ a↔b f (n) = O(g(n)) ≈ a ≤ b f (n) = Ω (g(n)) ≈ a ≥ b f (n) = Θ(g(n)) ≈ a = b f (n) = o(g(n)) ≈ a < b f (n) = ω (g(n)) ≈ a > b mp - 19 Comp 122 Limits lim [f(n) / g(n)] = 0 ⇒ f(n) ∈ ο(g(n)) n→∞ lim [f(n) / g(n)] < ∞ ⇒ f(n) ∈ Ο(g(n)) n→∞ 0 < lim [f(n) / g(n)] < ∞ ⇒ f(n) ∈ Θ(g(n)) n→∞ 0 < lim [f(n) / g(n)] ⇒ f(n) ∈ Ω (g(n)) n→∞ lim [f(n) / g(n)] = ∞ ⇒ f(n) ∈ ω(g(n)) n→∞ lim [f(n) / g(n)] undefined ⇒ can’t say n→∞ mp - 20 Comp 122 Properties Transitivity f(n) = Θ(g(n)) & g(n) = Θ(h(n)) ⇒ f(n) = Θ(h(n)) f(n) = O(g(n)) & g(n) = O(h(n)) ⇒...
View Full Document

Ask a homework question - tutors are online