Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -

Similar presentations


Presentation on theme: "CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -"— Presentation transcript:

1 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Motivation Big O notation Big Ω notation Big Θ notation Examples CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -

2 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Motivation Space and Time requirements for software depend on many factors We need a way to characterize the performance of an algorithm independent of factors such as hardware platform, OS, compiler, and implementation details. Big O, Big Ω, and Big Θ notation provide such a means. CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -

3 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Big O (Introduction) If computer C1 running algorithm program A takes T1(n) = c1 n2 milliseconds to reverse a list of n numbers and computer C2 takes twice as long to run the same program then T2(n) = c2 n2 = 2 c1 n2 It’s the same program in each case and so we would like to characterize the running times in a way that makes them equal. O(T1(n)) = O(T2(n)) = O(n2) CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -

4 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Big O (Intuition) To say that f(n) is O(g(n)) is to say that f(n) is bounded from above by some positive constant times g(n) for all n other than some finite number of specific exceptional values of n. CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -

5 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Big O (Definition) Suppose f and g are non-negative functions on the domain of natural numbers N = {0, 1, ... } f:N  + g:N  + Then f(n) is said to be O(g(n)) if and only if there exist constants c > 0 and n0 such that whenever n > n0, we have f(n)  c g(n) CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -

6 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Big O (Example) Let f(n) = n(n-1)/2 and g(n) = n2 Then f(n) is O(g(n)) because we can take c = 1 and n0 = 0, and then (n > 0) f(n) = n(n-1)/2 = ½ n2 - ½ n  1  n2 = g(n) CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -

7 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Big O (Example, cont.) Note: f(n) = ½ n2 - ½ n is also O(n3), O(n4), etc. f(n) is not O(n1). CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -

8 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Big O (More Examples) n is O(n) take c = 1, n0 = 0. 2n is O(n) take c = 2, n0 = 0 n is O(2n) take c = 1, n0 = 0 100 n is O(n) take c = 200, n0 = 2 e.g., when n=3:   200  3 CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -

9 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Big Ω (Definition) Suppose f and g are non-negative functions on the domain of natural numbers N = {0, 1, ... } f:N   g:N  + Then f(n) is said to be Ω(g(n)) if and only if there exists a constant c > 0 such that for all but a finite number of values of n, we have f(n)  c g(n) CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -

10 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Big Ω (Intuition) To say that f(n) is Ω(g(n)) is to say that f(n) is bounded from below by some positive constant times g(n) for all n other than some finite number of specific exceptional values of n. CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -

11 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Big Ω (Examples) n is Ω(n) take c = 1 2n is Ω(n) take c = 1 n is Ω(2n) take c = ½ 0.001 n + 1 is Ω(n) take c = 0.001 e.g., when n=3:    3 CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -

12 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Big Ω (Examples, cont.) 200 n is not Ω(n2) As n gets larger, n2 will eventually overtake 200 n CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -

13 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Big Θ (Definition) Suppose f and g are non-negative functions on the domain of natural numbers N = {0, 1, ... } f:N   g:N  + Then f(n) is said to be Θ(g(n)) if and only if f(n) is O(g(n)) and f(n) is Ω(g(n)) CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -

14 CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Big Θ (Examples) 2n is O(n) and 2n is Ω(n) so 2n is Θ(n) log2n is O(log n) and log2n is Ω(log n) so log2n is Θ(log n) Since changing the base of a logarithm is equivalent to multiplying the log by a constant, we can ignore the base when writing O(log n), Ω(log n), or Θ(log n) CSE 373, Copyright S. Tanimoto, Asymptotic Analysis -


Download ppt "CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -"

Similar presentations


Ads by Google