Algorithm Analysis (CSC 301 2015F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Outline] [EBoard] [Reading] [Lab] [Assignment]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Readings]
Reference: [Algorist]
Related Courses: [Walker (2014F)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker]
Overview
assert.T(n) <= 3T(n/3) + O(n^2).T(n) <= 3T(n/3) + O(n).T(n) <= 3T(n/3) + O(1).T(n) <= 3T(n/5) + O(n^2).T(n) <= 3T(n/5) + O(n).T(n) <= 3T(n/5) + O(1).T(n) <= 9T(n/3) + O(n^2).T(n) <= 9T(n/3) + O(n).T(n) <= 9T(n/3) + O(1).T(n) <= T(2n/3) + O(n^2).T(n) <= T(2n/3) + O(n).T(n) <= T(2n/3) + O(1).assert #include <assert.h>
main ()
{
assert(square(x) == x);
}
T(n) = 2*T(n/2) + dn
T(1) = 1
Conclusion T(N) is in O(nlogn)
Let's prove it. What techniques do you know? induction, contradiction, strong induction, construction, prove the inverse of the contrapositive
Goal is to prove T(n) is in O(nlogn). We need to prove that there exist an n0 and a c s.t. for all n > n0 T(n) <= c*nlogn.
The (strong) inductive hypothesis says ...
With your group
Base case: Exists c s.t. T(1) <= c*1log1. Whoops. log(1) = 0. So ... Choose a different base case (or base cases)
Does there exist a c s.t. T(2) <= c*2log2
Inductive hypothesis: For n > n0 T(n/2) <= c(n/2)*log(n/2)
General indicutive hypothesis. We are trying to prove CLAIM(n). We assume for all k < n, CLAIM(k) holds.
Inductive hypothesis: For n0 < k < n, T(k) <= cklogk
T(n) = 2*T(n/2) + dn
T(n) <= 2*c*n/2*log(n/2) + dn
; because n/2 < n and
; T(n/2) = c * n/2 * log(n/2)
T(n) <= c*n*log(n/2) + dn
; Cancel the 2 and 1/2
T(n) <= c*n*(log(n)+log(1/2)) + dn
; log(ab) = log(a) + log(b)
T(n) <= c*n*(log(n)+log(2^-1)) + dn
T(n) <= c*n*(log(n)-1) + dn
T(n) <= c*n*log(n) - cn + dn
T(n) <= c*n*log(n) + (d-c)n
; If c > d, (d-c)*n is negative
T(n) <= c*n*log(n) + (d-c)n <= c*n*log(n)
T(n) <= c*n*log(n) Q.E.D.
Revised hypothesis n0 and a c > d s.t. for all n > n0 T(n) <= c*nlogn.