Presentation is loading. Please wait.

Presentation is loading. Please wait.

Kompleksitas Waktu Asimptotik CSG3F3 Lecture 5. 2 Intro to asymptotic f(n)=an 2 + bn + c RMB/CSG3F3.

Similar presentations


Presentation on theme: "Kompleksitas Waktu Asimptotik CSG3F3 Lecture 5. 2 Intro to asymptotic f(n)=an 2 + bn + c RMB/CSG3F3."— Presentation transcript:

1 Kompleksitas Waktu Asimptotik CSG3F3 Lecture 5

2 2 Intro to asymptotic f(n)=an 2 + bn + c RMB/CSG3F3

3 3 Fitting curves to the data RMB/CSG3F3

4 4 f 1 (n)=0.0007772 n 2 + 0.00305n + 0.001  home computer data f 2 (n)=0.0001724 n 2 + 0.00040n + 0.100  desktop computer data RMB/CSG3F3

5 5 Coefficients (a,b,c) associated with particular –computers, –languages, and –compilers RMB/CSG3F3

6 6 Introducing the language of O- notation Dominant terms Ignoring the constant of proportionali ty RMB/CSG3F3

7 7 O(n 2 ) RMB/CSG3F3

8 8 Formal definition RMB/CSG3F3

9 9 Asymptotic Notations Big-oh (  ) Big-omega (  ) Big-theta (  ) Little-oh (  ) Little-omega (  ) RMB/CSG3F3

10 10  -notation  (g(n))={f(n): there exist positive constants c and nonnegative integer n o such that 0≤f(n) ≤cg(n) for all n ≥ n o } f(n) = O(g(n)) indicates that f(n) is a member of the set O(g(n)) RMB/CSG3F3

11 11RMB/CSG3F3

12 12 Proof 100n+5 = O(n 2 ) i.100n+n = 101n, 101n ≤ 101n 2, for all n≥5 c=101, n o =5 ii.100n+5n= 105n, 105n ≤ 105n 2, for all n≥1, c=105, n o =1 RMB/CSG3F3

13 13 1.T(n)=n+1024=O(n) 2.T(n)=1+2+…+n=O(n 2 ) 3.T(n)=10n 2 +4n+2=O(n 2 ) 4.T(n)=n 2 /10+2 n =O(2 n ) 5.T(n)=6*2 n +n 2 =O(2 n ) 6.T(n)=1 k + 2 k +…+n k =O(n k+1 ) 7.T(n)=log n 3 = O(log n) RMB/CSG3F3

14 14 8.T(n)=10 log 3 n =O(n) 9.T(n)=2n + 3 2 log n=O(n) 10.T(n)=n!=O(n n ) RMB/CSG3F3

15 15  -notation  (g(n))={f(n): there exist positive constants c and nonnegative integer n o such that f(n) ≥cg(n) ≥0 for all n ≥ n o } f(n) =  (g(n)) indicates that f(n) is a member of the set  (g(n)) RMB/CSG3F3

16 16RMB/CSG3F3

17 17 Proof 1.n 3 =  (n 2 ): n 3 ≥ cn 2 for all n ≥ 0, We can select c=1 and n 0 =0 2.3n +2 = Ω(n) : 3n + 2 ≥ 3n for n ≥ 1 3.10n 2 + 4n + 2 = Ω (n 2 ) : 10n 2 + 4n + 2 ≥ n 2 RMB/CSG3F3

18 18  -notation  (g(n)) ={f(n) : there exist positive constants c 1, c 2, and nonnegative integer n o such that c 2 g(n)≥f(n) ≥c 1 g(n)≥0 for all n ≥ n o } f(n) =  (g(n)) indicates that f(n) is a member of the set  (g(n)) RMB/CSG3F3

19 19RMB/CSG3F3

20 20 Proof ½n(n-1)=  (n 2 ) Prove the right inequality (upper bound) ½n(n-1)=½n 2 -½n ≤ ½n 2, for all n ≥ 0 Prove the left inequality (lower bound) ½n(n-1)=½n 2 -½n ≥ ½n 2 -½n ½n, for all n ≥ 2 = ¼n 2 c 1 = ½, c 2 = ¼, n 0 =2 RMB/CSG3F3

21 21 3n + 2 = Θ(n) as 3n + 2 ≥ 3n for all n ≥2, and 3n + 2 ≤ 4n for all n ≥2, so c 1 =3, c 2 =4 n 0 =2. RMB/CSG3F3

22 22 o-notation o(g(n))={f(n) : for any positive constants c >0, there exist a constant n o > 0 such that 0≤f(n) <cg(n) for all n ≥ n o } Example: 2n=o(n 2 ), but 2n 2 ≠o(n 2 ) RMB/CSG3F3

23 23  -notation  (g(n))={f(n): for any positive constants c>0, there exist a constant n o >0 such that f(n) >cg(n) ≥0 for all n ≥ n o } Example: n 2 /2=  (n), but n 2 /2≠  (n 2 ) RMB/CSG3F3

24 24 Property of asymptotic If f 1 (n)єO(g 1 (n)) and f 2 (n)єO(g 2 (n)), then f 1 (n) + f 2 (n) є O(max(g 1 (n),g 2 (n))) If f 1 (n)єO(g 1 (n)) and f 2 (n)єO(g 2 (n)), then f 1 (n)*f 2 (n) є O(g 1 (n)*g 2 (n)) (also work for  and  ) RMB/CSG3F3

25 25RMB/CSG3F3

26 26RMB/CSG3F3

27 27RMB/CSG3F3

28 28 Asymptotic Analogy RMB/CSG3F3

29 29 Complexity Classes RMB/CSG3F3

30 30 The Seven Most Important Functions 1.The Constant Function f(n) = c, for some fixed constant c. 2. The Linear Function f(n) = n. 3. The Quadratic Function f(n) = n 2. RMB/CSG3F3

31 31 The Seven Most Important Functions 4. Cubic function f(n) = n 3. Polynomials f(n) = a 0 + a 1 n + a 2 n 2 + …..+ a d n d integer d is called the degree of the polynomial. 5. Exponential Function f( n) = b n, where b is a positive constant, called the base and the argument n is the exponent. RMB/CSG3F3

32 32 The Seven Most Important Functions 6. Logarithm Function f(n) = log b n. 7. N-log-N Function f(n) = n log n. RMB/CSG3F3

33 33 Comparing Growth Rates constantlogarithmlinearn-log-nquadraticcubicexponent 1log nnn log nn2n2 n3n3 a n ( a > 1) RMB/CSG3F3

34 34 Growth of Function Values RMB/CSG3F3

35 35 Basic Efficiency Class classname 1 log n n n log n n 2 n 3 2 n n! constant logarithmic linear n log n quadratic cubic exponential factorial polynomial exponential RMB/CSG3F3

36 36 Exercises Determine whether the following assertions are true or false –n(n+1)/2 є O(n 3 ) –n(n+1)/2 є O(n 2 ) –n(n+1)/2 є  (n 3 ) –n(n+1)/2 є  (n) RMB/CSG3F3

37 37 References Levitin, Anany. The design and analysis of algorithms. Pearson Education. 2003. Cormen., Leiserson., Rivest. Introduction to algorithms. RMB/CSG3F3

38 38 Next.. Mathematical analysis of nonrecursive algorithm RMB/CSG3F3


Download ppt "Kompleksitas Waktu Asimptotik CSG3F3 Lecture 5. 2 Intro to asymptotic f(n)=an 2 + bn + c RMB/CSG3F3."

Similar presentations


Ads by Google