Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMPT 438 Algorithms Chapter 3 Asymptotic Notations.

Similar presentations


Presentation on theme: "CMPT 438 Algorithms Chapter 3 Asymptotic Notations."— Presentation transcript:

1 CMPT 438 Algorithms Chapter 3 Asymptotic Notations

2 When: Tuesday, September 22 3:30PM Where: RLC 105 Team based: one, two or three people per team Languages: C/C++ and Java IDEs: Visual Studio, Eclipse, NetBeans Event Schedule 3:30 – 5:30 pm – Contest 5:30 pm – Award Ceremony 5:30 pm – Pizza Party Register your team online or in RLC 203 (Find the registration list on the bulletin board) Contact Dr. Tina Tian for questions.

3 3 Some Simple Summation Formulas Arithmetic series: Geometric series: ▫Special case: x < 1: Harmonic series: Other important formulas:

4 Mathematical Induction Induction ▫Used to prove a sequence of statements (S(1), S(2), … S(n)) indexed by positive integers. Proof: ▫Basis step: prove that the statement is true for n = 1 ▫Inductive step: assume that S(n) is true and prove that S(n+1) is true for all n ≥ 1 The key to proving mathematical induction is to find case n “within” case n+1

5 Example Prove that: 2n + 1 ≤ 2 n for all n ≥ 3

6 More Examples

7 Asymptotic Notations How we indicate running times of algorithms Describe the running time of an algorithm as n grows to  O notation: asymptotic “less than”: f(n) “≤” g(n)  notation: asymptotic “greater than”: f(n) “≥” g(n)  notation: asymptotic “equality”: f(n) “=” g(n)

8 Asymptotic notations  -notation Intuitively  (g(n)) = the set of functions with the same order of growth as g(n)

9 Examples ▫ n 2 /2 –n/2 =  (n 2 )  ½ n 2 - ½ n ≤ ½ n 2  n ≥ 0  c 2 = ½  ½ n 2 - ½ n ≥ ½ n 2 - ½ n * ½ n (  n ≥ 2 ) = ¼ n 2  c 1 = ¼ ▫ n ≠  (n 2 ): c 1 n 2 ≤ n ≤ c 2 n 2  only holds for: n ≤ 1/ c 1

10 10 Examples ▫ 6n 3 ≠  (n 2 ): c 1 n 2 ≤ 6n 3 ≤ c 2 n 2  only holds for: n ≤ c 2 /6

11 11 Asymptotic notations (cont.) O-notation Intuitively: O(g(n)) = the set of functions with a smaller or same order of growth as g(n)

12 Examples ▫ 2n 2 = O(n 3 ): ▫ n 2 = O(n 2 ): ▫ 1000n 2 +1000n = O(n 2 ): ▫ n = O(n 2 ): 2n 2 ≤ cn 3  2 ≤ cn  c = 1 and n 0 = 2 n 2 ≤ cn 2  c ≥ 1  c = 1 and n 0 = 1 1000n 2 +1000n ≤ 1000n 2 + 1000n 2 = 2000n 2  c=2000 and n 0 = 1 n ≤ cn 2  cn ≥ 1  c = 1 and n 0 = 1

13 13 Asymptotic notations (cont.)  - notation Intuitively:  (g(n)) = the set of functions with a larger or same order of growth as g(n)

14 Examples ▫ 5n 2 =  (n) ▫ 100n + 5 ≠  (n 2 ) ▫ n =  (2n), n 3 =  (n 2 ), n =  (logn)  c, n 0 such that: 0  cn  5n 2  cn  5n 2  c = 1 and n 0 = 1  c, n 0 such that: 0  cn 2  100n + 5 100n + 5  100n + 5n (  n  1) = 105n cn 2  105n  n(cn – 105)  0 Since n is positive  cn – 105  0  n  105/c  contradiction: n cannot be smaller than a constant

15 Theorem ▫For any two functions f(n) and g(n), we have f(n) = θ(g(n)) if and only if f(n) = O(g(n)) and f(n) =  (g(n)) ▫ f(n) =  (g(n))  f = O(g(n)) and f =  (g(n))

16 Asymptotic notations (cont.) o – notation Used to denote an upper bound that is not asymptotically tight 2n = o(n 2 ) ? 2n 2 = o(n 2 ) ?

17 Asymptotic notations (cont.) w – notation Used to denote an lower bound that is not asymptotically tight n 2 /2= w(n) ? n 2 /2 = w(n 2 ) ?

18

19 Comparisons of Functions Transitivity: ▫ f(n) =  (g(n)) and g(n) =  (h(n))  f(n) =  (h(n)) ▫Same for O and  Reflexivity: ▫ f(n) =  (f(n)) ▫Same for O and  Symmetry: ▫ f(n) =  (g(n)) if and only if g(n) =  (f(n)) Transpose symmetry: ▫ f(n) = O(g(n)) if and only if g(n) =  (f(n))

20 Floors and Ceilings

21 21 Logarithms In algorithm analysis we often use the notation “ log n ” without specifying the base Binary logarithm

22 Polylogarithm lg k n Rule #1: Exponential functions grow faster than polynomial functions. Rule #2: Any positive polynomial function grows faster than any polylogarithmic function.

23 For each of the following pairs of functions, either f(n) is O(g(n)), f(n) is Ω(g(n)), or f(n) is Θ(g(n)). Determine which relationship is correct. ▫ f(n) = log n 2 ; g(n) = log n + 5 ▫ f(n) = n; g(n) = log n 2 ▫ f(n) = log log n; g(n) = log n ▫ f(n) = n; g(n) = log 2 n ▫ f(n) = n log n + n; g(n) = log n ▫ f(n) = 10; g(n) = log 10 ▫ f(n) = 2 n ; g(n) = 10n 2 ▫ f(n) = 2 n ; g(n) = 3 n f(n) =  (g(n)) f(n) =  (g(n)) f(n) = O(g(n)) f(n) =  (g(n)) f(n) =  (g(n)) f(n) =  (g(n)) f(n) = O(g(n))

24 Readings Chapter 4

25 Homework 2 ▫Programming assignment  Due before the last class  O(logn)  Algorithm description, run time analysis, source code and output Quiz?


Download ppt "CMPT 438 Algorithms Chapter 3 Asymptotic Notations."

Similar presentations


Ads by Google