Asymptotics Section 3.2 of Rosen Spring 2017

Slides:



Advertisements
Similar presentations
Asymptotics Section 3.2 of Rosen Spring 2010 CSCE 235 Introduction to Discrete Structures Course web-page: cse.unl.edu/~cse235 Questions:
Advertisements

 The running time of an algorithm as input size approaches infinity is called the asymptotic running time  We study different notations for asymptotic.
Chapter 3 Growth of Functions
The Growth of Functions
Asymptotic Growth Rate
Cutler/HeadGrowth of Functions 1 Asymptotic Growth Rate.
Asymptotic Analysis Motivation Definitions Common complexity functions
Tirgul 2 Asymptotic Analysis. Motivation: Suppose you want to evaluate two programs according to their run-time for inputs of size n. The first has run-time.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
Time Complexity Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
Mathematics Review and Asymptotic Notation
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.
Design and Analysis Algorithm Drs. Achmad Ridok M.Kom Fitra A. Bachtiar, S.T., M. Eng Imam Cholissodin, S.Si., M.Kom Aryo Pinandito, MT Pertemuan 04.
Asymptotic Analysis-Ch. 3
Growth of Functions. 2 Analysis of Bubble Sort 3 Time Analysis – Best Case The array is already sorted – no swap operations are required.
Time Complexity of Algorithms (Asymptotic Notations)
Analysis of Algorithm. Why Analysis? We need to know the “behavior” of algorithms – How much resource (time/space) does it use So that we know when to.
COP 3530 Spring2012 Data Structures & Algorithms Discussion Session Week 5.
Asymptotic Notations By Er. Devdutt Baresary. Introduction In mathematics, computer science, and related fields, big O notation describes the limiting.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Asymptotic Notation Faculty Name: Ruhi Fatima
Mathematical Foundations (Growth Functions) Neelima Gupta Department of Computer Science University of Delhi people.du.ac.in/~ngupta.
Asymptotic Complexity
CSCE 411 Design and Analysis of Algorithms
Analysis of Algorithms
COMP9024: Data Structures and Algorithms
COMP9024: Data Structures and Algorithms
Asymptotic Analysis.
Introduction to Algorithms
What is an Algorithm? Algorithm Specification.
Complexity analysis.
Analysis of algorithms
Analysis of Algorithms
COMP9024: Data Structures and Algorithms
Analysis of Algorithms
Growth of functions CSC317.
The Growth of Functions
Analysis of Algorithms
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
CS 3343: Analysis of Algorithms
CSCI 2670 Introduction to Theory of Computing
CSC 413/513: Intro to Algorithms
Analysis of Algorithms
Asymptotic Growth Rate
Analysis of Algorithms
Asymptotic Analysis.
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
CS 3343: Analysis of Algorithms
Orders of Growth Rosen 5th ed., §2.2.
Analysis of Algorithms
Advanced Analysis of Algorithms
Analysis of Algorithms
Fundamentals of the Analysis of Algorithm Efficiency
Master Theorem Section 8.3 of Rosen Spring 2017
What LIMIT Means Given a function: f(x) = 3x – 5 Describe its parts.
CSC 4170 Theory of Computation Time complexity Section 7.1.
Master Theorem Section 8.3 of Rosen Spring 2012
At the end of this session, learner will be able to:
Discrete Mathematics 7th edition, 2009
Analysis of algorithms
CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Advanced Analysis of Algorithms
CSC 4170 Theory of Computation Time complexity Section 7.1.
Big-O & Asymptotic Analysis
Master Theorem Section 8.3 of Rosen Spring 2013
CS 2604 Data Structures and File Management
Master Theorem Section 8.3 of Rosen Spring 2018
Algorithm Course Dr. Aref Rashad
Analysis of Algorithms
Presentation transcript:

Asymptotics Section 3.2 of Rosen Spring 2017 CSCE 235H Introduction to Discrete Structures (Honors) Course web-page: cse.unl.edu/~cse235h Questions: Piazza

Outline Introduction Asymptotic Proof techniques Limit Properties Definitions (Big O, Omega, Theta), properties Proof techniques 3 examples, trick for polynomials of degree 2, Limit method (l’Hôpital Rule), 2 examples Limit Properties Efficiency classes Conclusions

Introduction (1) We are interested only in the Order of Growth of an algorithm’s complexity How well does the algorithm perform as the size of the input grows: n  We have seen how to mathematically evaluate the cost functions of algorithms with respect to their input size n and their elementary operations However, it suffices to simply measure a cost function’s asymptotic behavior

Introduction (2): Magnitude Graph

Introduction (3) In practice, specific hardware, implementation, languages, etc. greatly affect how the algorithm behave Our goal is to study and analyze the behavior of algorithms in and of themselves, independently of such factors For example An algorithm that executes its elementary operation 10n times is better than one that executes it 0.005n2 times Also, algorithms that have running time n2 and 2000n2 are considered asymptotically equivalent

Outline Introduction Asymptotic Proof techniques Limit Properties Definitions (Big-O, Omega, Theta), properties Proof techniques Limit Properties Efficiency classes Conclusions

Big-O Definition Definition: Let f and g be two functions f,g:NR+. We say that f(n)  O(g(n)) (read: f is Big-O of g) if there exists a constant c  R+ and an noN such that for every integer n  n0 we have f(n)  cg(n) Big-O is actually Omicron, but it suffices to write “O” Intuition: f is asymptotically less than or equal to g Big-O gives an asymptotic upper bound \mathcal{O}

Big-Omega Definition Definition: Let f and g be two functions f,g: NR+. We say that f(n)  (g(n)) (read: f is Big-Omega of g) if there exists a constant c  R+ and an noN such that for every integer n  n0 we have f(n)  cg(n) Intuition: f is asymptotically greater than or equal to g Big-Omega gives an asymptotic lower bound \Omega()

Big-Theta Definition Definition: Let f and g be two functions f,g: NR+. We say that f(n)  (g(n)) (read: f is Big-Omega of g) if there exists a constant c1, c2  R+ and an noN such that for every integer n  n0 we have c1g(n)  f(n)  c2g(n) Intuition: f is asymptotically equal to g f is bounded above and below by g Big-Theta gives an asymptotic equivalence \Theta ()

Asymptotic Properties (1) Theorem: For f1(n)  O(g1(n)) and f2(n)  O(g2(n)), we have f1(n) + f2(n)  O( max{g1(n), g2(n)} ) This property implies that we can ignore lower order terms. In particular, for any polynomial with degree k such as p(n)=ank + bnk-1 + cnk-2 + …, p(n)  O(nk) More accurately, p(n)  (nk) In addition, this theorem gives us a justification for ignoring constant coefficients. That is for any function f(n) and a positive constant c cf(n)  (f(n))

Asymptotic Properties (2) Some obvious properties also follow from the definitions Corollary: For positive functions f(n) and g(n) the following hold: f(n)  (g(n))  f(n)  O(g(n)) ⋀ f(n)  (g(n)) f(n)  O(g(n))  g(n)  (f(n)) The proof is obvious and left as an exercise

Outline Introduction Asymptotic Proof techniques Limit Properties Definitions (big O, Omega, Theta), properties Proof techniques 3 examples, trick for polynomials of degree 2, Limit method (l’Hôpital Rule), 2 examples Limit Properties Efficiency classes Conclusions

Asymptotic Proof Techniques Proving an asymptotic relationship between two given function f(n) and g(n) can be done intuitively for most of the functions you will encounter; all polynomials for example However, this does not suffice as a formal proof To prove a relationship of the form f(n)(g(n)), where  is , , or , can be done using the definitions, that is Find a value for c (or c1 and c2) Find a value for n0 (But the above is not the only way.)

Asymptotic Proof Techniques: Example A Example: Let f(n)=21n2+n and g(n)=n3 Our intuition should tell us that f(n)  O(g(n)) Simply using the definition confirms this: 21n2+n  cn3 holds for say c=3 and for all nn0=8 So we found a pair c=3 and n0=8 that satisfy the conditions required by the definition QED In fact, an infinite number of pairs can satisfy this equation

Asymptotic Proof Techniques: Example B (1) Example: Let f(n)=n2+n and g(n)=n3. Find a tight bound of the form f(n)  (g(n)) Our intuition tells us that f(n)O(g(n)) Let’s prove it formally

Example B: Proof If n1 it is clear that n  n3 and n2  n3 Therefore, we have, as 1. and 2.: n2+n  n3 + n3 = 2n3 Thus, for n0=1 and c=2, by the definition of Big-O we have that f(n)=n2+n  O(g(n3))

Asymptotic Proof Techniques: Example C (1) Example: Let f(n)=n3+4n2 and g(n)=n2. Find a tight bound of the form f(n)  (g(n)) Here, 0ur intuition tells us that f(n)(g(n)) Let’s prove it formally

Example C: Proof For n1, we have n2  n3 For n0, we have n3  n3 + 4n2 Thus n1, we have n2  n3  n3 + 4n2 Thus, by the definition of Big- , for n0=1 and c=1 we have that f(n)=n3+4n2  (g(n2))

Asymptotic Proof Techniques: Trick for polynomials of degree 2 If you have a polynomial of degree 2 such as an2+bn+c you can prove that it is (n2) using the following values c1=a/4 c2=7a/4 n0= 2 max(|b|/a, sqrt(|c|)/a)

Outline Introduction Asymptotic Proof techniques Limit Properties Definitions (big O, Omega, Theta), properties Proof techniques 3 examples, trick for polynomials of degree 2, Limit method (l’Hôpital Rule), 2 examples Limit Properties Efficiency classes Conclusions

Limit Method: Motivation Now try this one: f(n)= n50+12n3log4n –1243n12 + 245n6logn + 12log3n – logn g(n)= 12 n50 + 24 log14 n43 – logn/n5 +12 Using the formal definitions can be very tedious especially one has very complex functions It is much better to use the Limit Method, which uses concepts from Calculus

Limit Method: The Process Say we have functions f(n) and g(n). We set up a limit quotient between f and g as follows The above can be proven using calculus, but for our purposes, the limit method is sufficient for showing asymptotic inclusions Always try to look for algebraic simplifications first If f and g both diverge or converge on zero or infinity, then you need to apply the l’Hôpital Rule Then f(n)O(g(n)) limn f(n)/g(n) = c>0 Then f(n)(g(n))  Then f(n)(g(n))

(Guillaume de) L’Hôpital Rule Theorem (L’Hôpital Rule): Let f and g be two functions, if the limit between the quotient f(n)/g(n) exists, Then, it is equal to the limit of the derivative of the numerator and the denominator limn f(n)/g(n) = limn f’(n)/g’(n)

Useful Identities & Derivatives Some useful derivatives that you should memorize (nk)’= k nk-1 (logb (n))’= 1/(n ln(b)) (f1(n)f2(n))’= f1’(n)f2(n)+f1(n)f2’(n) (product rule) (logb(f(n))’ = f’(n)/(f(n).lnb) (cn)’=ln(c)cn  careful! Log identities Change of base formula: logb(n)= logc(n)/logc(b) log(nk) = k log(n) log(ab) = log(a) + log(b)

L’Hôpital Rule: Justification (1) Why do we have to use L’Hôpital’s Rule? Consider the following function f(x)= (sin x )/x Clearly sin 0=0. So you may say that when x0, f(x)  0 However, the denominator is also  0, so you may say that f(x)   Both are wrong

L’Hôpital Rule: Justification (2) Observe the graph of f(x)= (sin x)/x = sinc x

L’Hôpital Rule: Justification (3) Clearly, though f(x) is undefined at x=0, the limit still exists Applying the L’Hôpital Rule gives us the correct answer lim x0 ((sin x )/x) = lim x0 (sin x )’/x’ = cos x/1 = 1

Limit Method: Example 1 Example: Let f(n) =2n, g(n)=3n. Determine a tight inclusion of the form f(n)  (g(n)) What is your intuition in this case? Which function grows quicker?

Limit Method: Example 1—Proof A Proof using limits We set up our limit: limn f(n)/g(n) = limn 2n/3n Using L’Hôpital Rule gets you no where limn 2n/3n =limn (2n)’/(3n)’=limn (ln2)(2n)/(ln3)(3n) Both the numerator and denominator still diverge. We’ll have to use an algebraic simplification

Limit Method: Example 1—Proof B Using algebra limn 2n/3n =limn (2/3)n Now we use the following Theorem w/o proof if  < 1 limn n = 1 if  = 1  if  > 1 Therefore we conclude that the limn (2/3)n converges to zero thus 2n  O(3n)

Limit Method: Example 2 (1) Example: Let f(n) =log2n, g(n)=log3n2. Determine a tight inclusion of the form f(n)  (g(n)) What is your intuition in this case?

Limit Method: Example 2 (2) We prove using limits We set up out limit limn f(n)/g(n) = limn log2n/log3n2 = limn log2n/(2log3n) Here we use the change of base formula for logarithms: logxn = logy n/logy x Thus: log3n = log2n / log23

Limit Method: Example 2 (3) Computing our limit: limn log2n/(2log3n) = limn log2n log23 /(2log2n) = limn (log23)/2 = (log23) /2  0.7924, which is a positive constant So we conclude that f(n)(g(n))

Outline Introduction Asymptotic Proof techniques Limit Properties Definitions (big O, Omega, Theta), properties Proof techniques 3 examples, trick for polynomials of degree 2, Limit method (l’Hôpital Rule), 2 examples Limit Properties Efficiency classes Conclusions

limn f1(n)  limn f2(n) = limn (f1(n)  f2(n)) Limit Properties A useful property of limits is that the composition of functions is preserved Lemma: For the composition  of addition, subtraction, multiplication and division, if the limits exist (that is, they converge), then limn f1(n)  limn f2(n) = limn (f1(n)  f2(n))

Complexity of Algorithms—Table 1, page 226 Constant O(1) Logarithmic O(log (n)) Linear O(n) Polylogarithmic O(logk (n)) Quadratic O(n2) Cubic O(n3) Polynominal O(nk) for any k>0 Exponential O(kn), where k>1 Factorial O(n!)

Conclusions Evaluating asymptotics is easy, but remember: Always look for algebraic simplifications You must always give a rigorous proof Using the limit method is (almost) always the best Use L’Hôpital Rule if need be Give as simple and tight expressions as possible

Summary Introduction Asymptotic Proof techniques Limit Properties Definitions (big O, Omega, Theta), properties Proof techniques 3 examples, trick for polynomials of degree 2, Limit method (l’Hôpital Rule), 2 examples Limit Properties Efficiency classes Conclusions