Understanding Big-Oh Notation in Time Complexity Analysis

Slide Note
Embed
Share

Big-Oh notation in algorithm analysis signifies how the runtime of an algorithm grows in relation to the input size. It abstractly characterizes the worst-case time complexity, disregarding constants and lower-order terms. The concept of Big-Oh, along with Big-Omega and Big-Theta, helps in comparing and understanding the efficiency of algorithms based on their growth rates. This notation simplifies the representation of time complexity in an implementation-independent manner, offering insights into the upper and lower bounds of algorithms' performance.


Uploaded on Sep 20, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Section 3.2

  2. Big-Oh Informal Notion f (n) O(g(n)) means that (within a constant factor) g(n) eventually overtakes (dominates) f (n). Captures the idea of worst-case. Disregards constant factors & lower order terms. Characterizes time complexity in an abstract fashion that is implementation independent. Defines a set of functions that have the given function g as an upper-bound

  3. Big-Oh

  4. Big-Oh proofs

  5. Complexity Classes

  6. Comparing Complexity Classes Times of more than 10100 years are indicated with an *.

  7. Function growth rates Logarithmic scale!

  8. Big-Omega

  9. Big-Omega Formal Definition + + = ( ( )) g n { ( )| f n : : :0 ( ) ( )} f n c R n N n n cg n 0 0 This captures the notion of lower bound, just as Big-Oh captures the notion of upper bound.

  10. Big-Theta

  11. Big-Theta Formal Definition + + = c c ( ( )) { ( )| g n n , : : f n R n N 1 ( ) 2 0 c g n :0 ( ) f n ( )} n c g n 0 1 2 Big-Theta partitions the class of functions into equivalence classes. Functions that are in the same equivalence class are asymptotically equivalent. That is they have the same order of growth.

  12. Big-Oh Properties Transitivity f (n) O (g(n)) g(n) O (h(n)) f(n) O (h(n)) Addition f (n) + g(n)) O (max{f(n), g(n)}) Polynomials a0 + a1n+ + adnd O (nd) Base of logarithms logan O (logb n) Powers in logarithms log (n2) O (logn) Exponents 3n O (2n) 2 ( ) n n ( ) a O a

  13. Big-Oh Formal Definition ( ( n g O + + = )) { ( | ) n : : : 0 ( ) ( )} f c R n N n n f n cg n 0 0 Since this definition uses an inequality, a given function can have many upper bounds. For example, 2n2+3 O(n2) 2n2+3 O(n3) Although both of these examples are true, the first provides a tighter characterization of 2n2+3

  14. Big-Oh proofs Show that f(x) = x2 + 2x + 1 is O(x2) In other words, show that x2 + 2x + 1 c*x2 Where c is some constant For all x greater than some n0 We know that 2x2 2x whenever x 1 And we know that x2 1 whenever x 1 So we replace 2x+1 with 2x2 + x2 We then end up with x2 + 2x2 + x2 = 4x2 This yields 4x2 c*x2 Thus, for input sizes 1 or greater, when the constant is 4 or greater, f(x) is O(x2) Note: We could have chosen values for c and n0 that were different

  15. Sample Big-Oh problems Show that f(x) = x2 + 1000 is O(x2) In other words, show that x2 + 1000 c*x2 We know that x2 > 1000 whenever x > 31 Thus, we replace 1000 with x2 This yields 2x2 c*x2 Thus, f(x) is O(x2) for all x > 31 when c 2

  16. Sample Big-Oh problems Show that f(x) = 3x+7 is O(x) In other words, show that 3x+7 c*x We know that x > 7 whenever x > 7 Uh huh . So we replace 7 with x This yields 4x c*x Thus, f(x) is O(x) for all x > 7 when c 4

  17. A variant of the last question Show that f(x) = 3x+7 is O(x2) In other words, show that 3x+7 c*x2 We know that x > 7 whenever x > 7 Uh huh . So we replace 7 with x This yields 4x < c*x2 This will also be true for x > 7 when c 1 Thus, f(x) is O(x2) for all x > 7 when c 1

Related