An Upper Bound gn is an upper bound
An Upper Bound • g(n) is an upper bound on f(n). C++ Review EECE 352 1
A Lower Bound • g(n) is a lower bound for f(n) C++ Review EECE 352 2
A Tight Bound • We say that g(n) is an asymptotically tight bound for f(n). C++ Review EECE 352 3
Transitivity and imply • The operators are transitive. • They are also Reflexive. C++ Review EECE 352 4
Exercises • Show that for any constants a and b >0. • Is 2 n+1 = O(2 n) ? • Is 22 n = O(2 n) ? • Rewrite in Big-O notation: C++ Review EECE 352 5
Rules to Remember • If T 1(n) = O(f(n)) and T 2(n)=O(g(n)) then – T 1(n) + T 2(n) = max(O(f(n)), O(g(n))) – T 1(n)*T 2(n) = O(f(n)*g(n)) • If T(n) is a polynomial of degree n, then T(x) = (xn). • logkn = O(n) for any constant k. C++ Review EECE 352 6
Sample Functions C++ Review EECE 352 7
Analyzing Algorithms • Model of idealized computer: – The usual set of operators, all take constant time. – No fancy operators. – Infinite memory. • Find the amount of time it takes to finish as a function of the input size. C++ Review EECE 352 8
Loops • A loop of size n that does something that takes time k will take nk total time. • This applies recursively. If the something is also a loop of size n it will take n 2 k. • And so on. . . Recursion • Could be just a for loop, could be worse. C++ Review EECE 352 9
- Slides: 9