240 likes | 453 Views
Chapter 3 Growth of Functions. ex.2.3-4 p39 Sort A[1…n] by recursively sorting A[1…n-1] then insert A[n] Write recurrence for run time. Solution: T(n) = T(n-1) + O(n) Rationale for O(n)? What is the solution of this recurrence?. (defined as set of functions).
E N D
ex.2.3-4 p39 Sort A[1…n] by recursively sorting A[1…n-1] then insert A[n] Write recurrence for run time. Solution: T(n) = T(n-1) + O(n) Rationale for O(n)? What is the solution of this recurrence?
(defined as set of functions) Used to denote worst case, as in insertion sort T(n) = O(n2) Allows for possibility that f(n) = cg(n) for large n To prove T(n) = O(n), find a combination of c and n0 (may not be unique)
Used to denote best case run time Allows for possibility that f(n) = cg(n) for large n To prove T(n) = W(n), find a combination of c and n0 (may not be unique)
T(n) = Q(n) iff T(n) = O(n) and T(n) = W(n) Theorem 3.1 At large n, f(n) and g(n) are equal within a constant factor To prove T(n) = Q(n), use Theorem 3.1
Ex 3.1-1 text p52: show that max(f(n),g(n)) = Q(f(n) + g(n))
When is equals the case? Can we assign a value to n0? Let n0 be the value where f(n) and g(n) become non-negative When is equals the case?
Informal proof of Q notation If g(n) is dominant term in limit f(n), then f(n) = Q(g(n)) n →∞ Example: Show by informal proof that (n+a)b = Q(nb) real a & b b > 0 Binomial expansion: (n+a)b = Cbnb + Cb-1nb-1+…+C0 Since nb is dominant term at large n, (n+a)b = Q(nb)
Formal proof that (n+a)b = Q(nb) Ex 3.1-2 text p52
a can be < 0 but a < |a| Replacing |a| by something larger strengths inequality Same argument as above Determines n0 Combine 2 inequalities RTA
Floors and Ceilings More properties given on text p54
Little o notation Analogous to a < b for real numbers f(n) = o(g(n)) means f(n) is a member of a set of function such that for any c > 0 (no matter how small) 0 < f(n) < cg(n) all n > n0 Can only be true if f(n) is insignificant relative to g(n) at large n Equivalent to limit f(n)/g(n) = 0 n →∞ g(n) is strictly an asymptotic upper bound on f(n) equality of f(n) and g(n) is excluded 2n = o(n2) 2n2is not o(n2) text p 50
Little omega notation Analogous to a > b for real numbers f(n) = w(g(n)) means f(n) is a member of a set of function such that for any c > 0 (no matter how large) 0 < cg(n) < f(n) all n > n0 Can only be true if g(n) is insignificant relative to f(n) at large n Equivalent to limit g(n)/f(n) = 0 n →∞ g(n) is strictly an asymptotic lower bound on f(n) equality of f(n) and g(n) is excluded n2/2 = w(n) n2/2 is not w(n2) text p51
f(n) = o(g(n)) implies f(n) = O(g(n)) If for any c > 0, 0 < f(n) < cg(n) then there exist some c > 0 such that 0 < f(n) < cg(n) Similarly f(n) = w(g(n)) implies f(n) = W(g(n)) What is wrong with this argument?
Important math from Section 3.2
Asymptotic notation in equations Alone on right side: n = o(n2) set definition Part of an equation: f(n) = 2n2 + Q(n) = Q(n2) In recursive relation T(n) = T(n-1) + Q(n) says overhead is linear Both sides: ΣQ(fk(n)) = Q(Σfk(n)) sum of Qs equals Q of sum
Cpt S 450 Spring 2014 [All problems are from Cormen et al, 3rd Edition] Homework Assignment 2: due 1/29/14 1. Use Stirling’ approximation, Eq(3.18) p 57, to show that n! = o(nn) and n! = w(2n) and to get an informal proof that lg(n!) = Q(nlgn) 2. ex 3.2-7 p 60 3. prob 3-2 p 61