1 / 14

Lecture 3

Lecture 3. Analysis of Algorithms, Part II. Plan for today. Finish Big Oh , more motivation and examples, do some limit calculations. Little Oh, Theta notation Start Recurrences . Ex.1 ch.1 in textbook Tower of Hanoi. Binary search recurrence.

loman
Download Presentation

Lecture 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 3 Analysis of Algorithms, Part II

  2. Plan for today • Finish Big Oh, more motivation and examples, do some limit calculations. • Little Oh, Theta notation • Start Recurrences. • Ex.1 ch.1 in textbook • Tower of Hanoi. • Binary search recurrence

  3. An example of Proof by Induction for a Recursive Program • Ex 1 Ch 1 textbook • Function: int g(int n) if n<=1 return n else return 5 g(n-1) + 6 g(n-2) • Prove that g(n)=3n – 2n

  4. More about Big Oh • lim a(n)/b(n) = constant if and only if a(n) < c b(n) for all n sufficiently large • This allows to estimate, when we do not know how to compute limits. • Example: the Harmonic numbers H(n) = 1+1/2+1/3+1/4+…+1/n < 1+1+…+1=n Hence H(n)=O(n).

  5. Complexity Classes • Big Oh allows to talk about algorithms with asymptotically comparable running times • Most important in practice (tractable problems): • Logarithmic and poly-logarithmic: log n, logkn • Polynomial: n, n2, n3, …, nk, .. • Untractable problems: • Exponential: 2n, 3n, 2n^2, … • Higher (super-exponential): 22^n, 2n^n, …

  6. Most efficient: logarithmic and poly-logarithmic • Functions which are O(log n) or polynomials in log n. • Examples: • Base of the logarithm is irrelevant inside Big Oh: logb n (any base b) = O(log n) • Harmonic series: 1+1/2+1/3+…+ 1/n = O(log n) • Most efficient data structures have search time O(log n) or O(log2n)

  7. Upper bound for Harmonic series • Hn=1+1/2+1/3+…+1/n < 1+1+…+1 = n • So Hn = O(n), but this estimate is not good enough • To prove Hn = O(log n) need more advanced calculus (Riemann integrals) 1/x

  8. Examples • Binary search: main paradigm, search with O(log n) time per operation • Binary search trees: worst case time is linear, but on average search time is log n • B-trees (used in databases) and B+ trees • AVL-trees • Red-black trees • Splay trees, finger trees • Dynamic convex hull algorithms: O(log2n) time per update operation

  9. Polynomial Time • Most efficient: linear timeO(n) • Depth-first and breadth-first search • Connectivity, cycles in graphs • Good: O(n log n): • Sorting • Convex hulls (in Computational Geometry) • QuadraticO(n2) • Shortest paths in graphs • Minimum spanning tree • CubicO(n3) • All pairs shortest path • Matrix multiplication (naïve) • O(n5)? O(n6)? • Robot Motion Planning Problems with few (5, 6,…) degrees of freedom

  10. Exponential time • Towers of Hanoi O(2n) • Travelling Salesman • Satisfiability of boolean formulas and circuits Super-exponential time • Many Robot Motion Planning Problems with many (n) degrees of freedom O(22^n)

  11. Relative Growth exponential polynomial logarithmic

  12. Largest instance solvable

  13. Big Omega and Theta • Big Oh and Small Oh give Upper bounds on functions • Reverses the role in Big Oh: • f(n) = Omega(g(n)) iff g(n) = O(f(n)) lim g(n) / f(n) < constant • Big Oh gives upper bounds, Omega notation gives lower bounds • Theta: both Big Oh and Omega

  14. Examples • f(n) = n2+2n-10 and g(n)=3n2-23 are Theta(n2) and Theta of each other. Why? • f(n)=log2 n and g(n)=log3 n are Theta of each other (logarithm base doesn’t count) • f(n)=2n and g(n)=3n are NOT Theta of each other. f(n)=o(g(n)), grows much slower. Because lim 2n/3n=0.

More Related