Asymptotic Analysis Motivation Big O notation Big notation
Asymptotic Analysis • Motivation • Big O notation • Big Ω notation • Big Θ notation • Examples CSE 373, Copyright S. Tanimoto, 2002 1
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, 2002 2
Big O (Introduction) If computer C 1 running algorithm program A takes T 1(n) = c 1 n 2 milliseconds to reverse a list of n numbers and computer C 2 takes twice as long to run the same program then T 2(n) = c 2 n 2 = 2 c 1 n 2 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(T 1(n)) = O(T 2(n)) = O(n 2) CSE 373, Copyright S. Tanimoto, 2002 3
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, 2002 4
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 n 0 such that whenever n > n 0, we have f(n) c g(n) CSE 373, Copyright S. Tanimoto, 2002 5
Big O (Example) Let f(n) = n(n-1)/2 and g(n) = n 2 Then f(n) is O(g(n)) because we can take c = 1 and n 0 = 0, and then ( n > 0) f(n) = n(n-1)/2 = ½ n 2 - ½ n 1 n 2 = g(n) CSE 373, Copyright S. Tanimoto, 2002 6
Big O (Example, cont. ) Note: f(n) = ½ n 2 - ½ n is also O(n 3), O(n 4), etc. f(n) is not O(n 1). CSE 373, Copyright S. Tanimoto, 2002 7
Big O (More Examples) n is O(n) ---- take c = 1, n 0 = 0. 2 n is O(n) ---- take c = 2, n 0 = 0 n is O(2 n) ---- take c = 1, n 0 = 0 100 n + 50 is O(n) e. g. , when n=3: -- take c = 200, n 0 = 2 100 3 + 50 200 3 CSE 373, Copyright S. Tanimoto, 2002 8
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, 2002 9
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, 2002 10
Big Ω (Examples) n is Ω(n) ---- take c = 1 2 n is Ω(n) ---- take c = 1 n is Ω(2 n) ---- take c = ½ 0. 001 n + 1 is Ω(n) e. g. , when n=3: -- take c = 0. 001 3 + 1 0. 001 3 CSE 373, Copyright S. Tanimoto, 2002 11
Big Ω (Examples, cont. ) 200 n is not Ω(n 2) As n gets larger, n 2 will eventually overtake 200 n CSE 373, Copyright S. Tanimoto, 2002 12
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, 2002 13
Big Θ (Examples) 2 n is O(n) and 2 n is Ω(n) so 2 n is Θ(n) log 2 n is O(log n) and log 2 n is Ω(log n) so log 2 n 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, 2002 14
- Slides: 14