1 / 9

General rules: Find big-O

General rules: Find big-O. f (n) = k = O(1) f ( n ) = a k n k + a k-1 n k-1 + . . . + a 1 n 1 + a 0 = O( n k ) Other functions, try to find the dominant term according to the growth rate of the well known functions Example f(n)=5n 2 +2 n f(n)=5n 2 +3nlog(n).

psyche
Download Presentation

General rules: Find big-O

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. General rules: Find big-O • f(n) = k = O(1) • f(n) = aknk + ak-1nk-1 + . . . + a1n1 + a0 = O(nk) • Other functions, try to find the dominant term according to the growth rate of the well known functions • Example f(n)=5n2+2n f(n)=5n2+3nlog(n)

  2. A Hierarchy of Growth Rates

  3. A Hierarchy of Growth Rates (cont’d)

  4. Theorem • The function is big-O of its successors • 1 • Logb(n) • N • nLogb(n) • N2 • 2n • 3n • n! • nn

  5. Big-Omega Notation • Definition: f(n)= (g(n))if there exist positive constants c and N such that f(n)  cg(n) for all n  N • This says that function f(n) grows at a rate no slower than g(n); thus g(n) is a lower bound on f(n) • Note the equivalence • f(n)= (g(n)) iff g(n)= O(f(n)) • graph

  6. Big-Theta Notation • Definition: f(n)= (g(n))if there exist positive constants c1, c2, and N such that c1g(n)f(n)  c2g(n) for all n  N • Note that f(n)= (g(n))ifff(n)= O(g(n))and f(n)= (g(n)) • This says that f(n) grows at the same rate as g(n) • Graph

  7. Summary of Notations • Big-O Notation gives an upper bound for a function to within a constant factor f(n)= O(g(n)) • Big-Omega Notation gives a lower bound for a function to within a constant function f(n)= (g(n)) • Big-Theta Notation bounds a function to within constant factors f(n)= (g(n))

  8. General rules: Find big-O • f(n) = k = O(1) • f(n) = aknk + ak-1nk-1 + . . . + a1n1 + a0 = O(nk) • Other functions, try to find the dominant term according to the above theorem • Example f(n)=5n2+2n f(n)=5n2+3nlog(n)

  9. Big-O for some algorithms • Linear search • Binary search

More Related