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

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

Discrete Structures CISC 2315
 The running time of an algorithm as input size approaches infinity is called the asymptotic running time  We study different notations for asymptotic.
Estimating Running Time Algorithm arrayMax executes 3n  1 primitive operations in the worst case Define a Time taken by the fastest primitive operation.
The Growth of Functions
Cutler/HeadGrowth of Functions 1 Asymptotic Growth Rate.
© 2004 Goodrich, Tamassia 1 Lecture 01 Algorithm Analysis Topics Basic concepts Theoretical Analysis Concept of big-oh Choose lower order algorithms Relatives.
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Analysis of Algorithms
Analysis of Algorithms (pt 2) (Chapter 4) COMP53 Oct 3, 2007.
25 June 2015Comp 122, Spring 2004 Asymptotic Notation, Review of Functions & Summations.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 2 Elements of complexity analysis Performance and efficiency Motivation: analysis.
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 1. 2 Big Oh and other notations Introduction Classifying functions by their asymptotic growth Theta, Little oh,
Chapter 2: Algorithm Analysis Big-Oh and Other Notations in Algorithm Analysis Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
CSE 373 Data Structures and Algorithms Lecture 4: Asymptotic Analysis II / Math Review.
Algorithm analysis and design Introduction to Algorithms week1
Analysis of Algorithms Lecture 2
Algorithm Analysis. Algorithm Def An algorithm is a step-by-step procedure.
1 ©2008 DEEDS Group Introduction to Computer Science 2 - SS 08 Asymptotic Complexity Introduction in Computer Science 2 Asymptotic Complexity DEEDS Group.
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
Analysis of Algorithms
Analysis of Algorithms1 The Goal of the Course Design “good” data structures and algorithms Data structure is a systematic way of organizing and accessing.
CSC 201 Analysis and Design of Algorithms Lecture 04: CSC 201 Analysis and Design of Algorithms Lecture 04: Time complexity analysis in form of Big-Oh.
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
CS 3343: Analysis of Algorithms
1 COMP3040 Tutorial 1 Analysis of algorithms. 2 Outline Motivation Analysis of algorithms Examples Practice questions.
Asymptotic Analysis-Ch. 3
Coursenotes CS3114: Data Structures and Algorithms Clifford A. Shaffer Department of Computer Science Virginia Tech Copyright ©
Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =
1 o-notation For a given function g(n), we denote by o(g(n)) the set of functions: o(g(n)) = {f(n): for any positive constant c > 0, there exists a constant.
Zeinab EidAlgorithm Analysis1 Chapter 4 Analysis Tools.
Algorithm Efficiency There are often many approaches (algorithms) to solve a problem. How do we choose between them? At the heart of a computer program.
Design and Analysis of Algorithms Chapter Asymptotic Notations* Dr. Ying Lu August 30, RAIK.
Growth of Functions. 2 Analysis of Bubble Sort 3 Time Analysis – Best Case The array is already sorted – no swap operations are required.
Introduction to Analysis of Algorithms CS342 S2004.
Time Complexity of Algorithms
Time Complexity of Algorithms (Asymptotic Notations)
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
General rules: Find big-O f(n) = k = O(1) f(n) = a k n k + a k-1 n k a 1 n 1 + a 0 = O(n k ) Other functions, try to find the dominant term according.
Algorithm Analysis Part of slides are borrowed from UST.
Introduction to Algorithms Lecture 2 Chapter 3: Growth of Functions.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
David Meredith Growth of Functions David Meredith
UNIT-I FUNDAMENTALS OF THE ANALYSIS OF ALGORITHM EFFICIENCY ANALYSIS AND DESIGN OF ALGORITHMS CHAPTER 2:
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 2 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
CSE 373: Data Structures and Algorithms Lecture 4: Math Review/Asymptotic Analysis II 1.
13 February 2016 Asymptotic Notation, Review of Functions & Summations.
Asymptotic Notation Faculty Name: Ruhi Fatima
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
 Discrete numeric functions(or numeric functions): The functions whose domain is the set of natural numbers and whose range is the set of real numbers.
DR. Gatot F. Hertono, MSc. Design and Analysis of ALGORITHM (Session 2)
LECTURE 2 : fundamentals of analysis of algorithm efficiency Introduction to design and analysis algorithm 1.
1 COMP9024: Data Structures and Algorithms Week Two: Analysis of Algorithms Hui Wu Session 2, 2014
Lecture 3COMPSCI.220.S1.T Running Time: Estimation Rules Running time is proportional to the most significant term in T(n) Once a problem size.
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Introduction to Algorithms
What is an Algorithm? Algorithm Specification.
Growth of functions CSC317.
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
BIG-OH AND OTHER NOTATIONS IN ALGORITHM ANALYSIS
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
Advanced Analysis of Algorithms
Fundamentals of the Analysis of Algorithm Efficiency
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Advanced Analysis of Algorithms
Presentation transcript:

Kompleksitas Waktu Asimptotik CSG3F3 Lecture 5

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

3 Fitting curves to the data RMB/CSG3F3

4 f 1 (n)= n n  home computer data f 2 (n)= n n  desktop computer data RMB/CSG3F3

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

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

7 O(n 2 ) RMB/CSG3F3

8 Formal definition RMB/CSG3F3

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

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

11RMB/CSG3F3

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 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 8.T(n)=10 log 3 n =O(n) 9.T(n)=2n log n=O(n) 10.T(n)=n!=O(n n ) RMB/CSG3F3

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

16RMB/CSG3F3

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 ≥ n 2 + 4n + 2 = Ω (n 2 ) : 10n 2 + 4n + 2 ≥ n 2 RMB/CSG3F3

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

19RMB/CSG3F3

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 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 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  -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 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

25RMB/CSG3F3

26RMB/CSG3F3

27RMB/CSG3F3

28 Asymptotic Analogy RMB/CSG3F3

29 Complexity Classes RMB/CSG3F3

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 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 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 Comparing Growth Rates constantlogarithmlinearn-log-nquadraticcubicexponent 1log nnn log nn2n2 n3n3 a n ( a > 1) RMB/CSG3F3

34 Growth of Function Values RMB/CSG3F3

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 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 References Levitin, Anany. The design and analysis of algorithms. Pearson Education Cormen., Leiserson., Rivest. Introduction to algorithms. RMB/CSG3F3

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