David Evans CS150: Computer Science University of Virginia Computer Science Lecture 14: Asymptotic Growth.

Slides:



Advertisements
Similar presentations
Algorithms Algorithm: what is it ?. Algorithms Algorithm: what is it ? Some representative problems : - Interval Scheduling.
Advertisements

Program Efficiency & Complexity Analysis
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 13: Of On and Off Grounds Sorting.
 The running time of an algorithm as input size approaches infinity is called the asymptotic running time  We study different notations for asymptotic.
CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 16: Quicker Sorting.
Asymptotic Growth Rate
Cutler/HeadGrowth of Functions 1 Asymptotic Growth Rate.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 2 Elements of complexity analysis Performance and efficiency Motivation: analysis.
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.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 1. 2 Big Oh and other notations Introduction Classifying functions by their asymptotic growth Theta, Little oh,
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
Asymptotic Notations Iterative Algorithms and their analysis
David Evans Class 12: Quickest Sorting CS150: Computer Science University of Virginia Computer Science Rose Bush by Jacintha.
David Evans Class 13: Quicksort, Problems and Procedures CS150: Computer Science University of Virginia Computer Science.
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
Iterative Algorithm Analysis & Asymptotic Notations
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 12: Decrypting Work Circle Fractal.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 2: Orders of Growth
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
CSCI 3160 Design and Analysis of Algorithms Tutorial 1
Asymptotic Analysis-Ch. 3
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
CS 61B Data Structures and Programming Methodology July 10, 2008 David Sun.
Fundamentals of Algorithms MCS - 2 Lecture # 8. Growth of Functions.
David Evans Class 20: Quick Sorting CS200: Computer Science University of Virginia Computer Science Queen’s University,
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 12: Something about Sneezewort From.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 3: Levels of Abstraction
Class 21: Introducing Complexity David Evans cs302: Theory of Computation University of Virginia Computer Science.
The Time Complexity of an Algorithm Specifies how the running time depends on the size of the input. CSE 3101Z Design and Analysis of Algorithms.
Growth of Functions. 2 Analysis of Bubble Sort 3 Time Analysis – Best Case The array is already sorted – no swap operations are required.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Time Complexity of Algorithms
1 Asymptotic Notations Iterative Algorithms and their analysis Asymptotic Notations –Big O,  Notations Review of Discrete Math –Summations –Logarithms.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 12: QuickSorting Queen’s University,
COP 3530 Spring2012 Data Structures & Algorithms Discussion Session Week 5.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 9: Of On and Off Grounds Sorting Coffee.
Spring 2015 Lecture 2: Analysis of Algorithms
CS 150: Analysis of Algorithms. Goals for this Unit Begin a focus on data structures and algorithms Understand the nature of the performance of algorithms.
Lecture aid 1 Devon M. Simmonds University of North Carolina, Wilmington CSC231 Data Structures.
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 14: P = NP?
DR. Gatot F. Hertono, MSc. Design and Analysis of ALGORITHM (Session 2)
1 Section 5.6 Comparing Rates of Growth We often need to compare functions ƒ and g to see whether ƒ(n) and g(n) are about the same or whether one grows.
Lecture 13: Quicksorting CS200: Computer Science
Asymptotic Analysis.
Introduction to Algorithms
David Kauchak CS52 – Spring 2015
Growth of functions CSC317.
Lecture 16: Quickest Sorting CS150: Computer Science
Class 14: Intractable Problems CS150: Computer Science
Lecture 11: All Sorts CS200: Computer Science University of Virginia
Asymptotic Growth Rate
Asymptotic Analysis.
Lecture 13: Cost of Sorts CS150: Computer Science
Lecture 22: P = NP? CS200: Computer Science University of Virginia
Lecture 10: Quicker Sorting CS150: Computer Science
Advanced Analysis of Algorithms
Big-O, Ω, ϴ Trevor Brown CSC263 Tutorial 1 Big-O, Ω, ϴ Trevor Brown
CS200: Algorithms Analysis
Lecture 15: Quicker Sorting CS150: Computer Science
Algorithm Analysis T(n) O() Growth Rates 5/21/2019 CS 303 – Big ‘Oh’
Lecture 11: Sorting Grounds and Bubbles
Estimating Algorithm Performance
Big Omega, Theta Defn: T(N) = (g(N)) if there are positive constants c and n0 such that T(N)  c g(N) for all N  n0 . Lingo: “T(N) grows no slower than.
Presentation transcript:

David Evans CS150: Computer Science University of Virginia Computer Science Lecture 14: Asymptotic Growth

2 Lecture 14: Asymptotic Growth Proof Techniques Theorem: There exists a polygon with four sides. Proof: It is a polygon. It has four sides. QED. What kind of proof is this?

3 Lecture 14: Asymptotic Growth Proof by Construction We can prove a “there exists an X with property Y” theorem, but showing an X that has property Y O(f) means “there are positive constants c and n 0 such that g(n)  cf(n) for all n  n 0 So, to prove g is in O(f) we need to find c and n 0 and show that g(n)  cf(n) for all n  n 0

4 Lecture 14: Asymptotic Growth Dis-Proof by Construction To prove g is not in O(f) : O(f) means: there are positive constants c and n 0 such that g(n)  cf(n) for all n  n 0 So, to prove g is not in O(f) we need to find a way given any c and n 0, to find an n  n 0 such that g(n) > cf(n).

5 Lecture 14: Asymptotic Growth Growth Notations g  O(f) (“Big-Oh”) g grows no faster than f (upper bound) g   (f) (“Theta”) g grows as fast as f (tight bound) g   (f) (“Omega”) g grows no slower than f (lower bound)

6 Lecture 14: Asymptotic Growth The Sets O(f ) and Ω(f ) f O(f)O(f) Functions that grow no faster than f Ω(f)Ω(f) Functions that grow no slower than f Increasingly fast growing functions

7 Lecture 14: Asymptotic Growth O and Ω Examples n is in  ( n ) –Yes, pick c = 1 10n is in  ( n ) –Yes, pick c = 1 Is n 2 in  ( n ) ? –Yes! (pick c = 1 ) n is in O(n) –Yes, pick c = 1 10n is in O(n) –Yes, pick c = 10 n 2 is not in O(n) –Pick n > c g is in O (f) iff there are positive constants c and n 0 such that g(n) ≤ cf(n) for all n ≥ n 0. g is in Ω (f) iff there are positive constants c and n 0 such that g(n) ≥ cf(n) for all n ≥ n 0.

8 Lecture 14: Asymptotic Growth Example Is n in  (n 2 ) ? g is in Ω (f) iff there are positive constants c and n 0 such that g(n) ≥ cf(n) for all n ≥ n 0. n  cn 2 for all n  n 0 1  cn for all n  n 0 No matter what c is, I can make this false by using n = (1/c + 1)

9 Lecture 14: Asymptotic Growth Θ (“Theta”): Tight Bound g is Θ(f ) iff g is in O ( f ) and g is in  ( f )

10 Lecture 14: Asymptotic Growth The Sets O(f ), Ω(f ), and Θ(f ) f O(f)O(f) Functions that grow no faster than f Ω(f)Ω(f) Functions that grow no slower than f Θ(f)Θ(f) How big are O(f ), Ω(f ), and Θ(f ) ? Increasingly fast growing functions

11 Lecture 14: Asymptotic Growth Θ Examples Is 10n in Θ ( n ) ? –Yes, since 10n is  ( n ) and 10n is in O(n) Doesn’t matter that you choose different c values for each part; they are independent Is n 2 in Θ ( n ) ? –No, since n 2 is not in O ( n ) Is n in Θ ( n 2 ) ? –No, since n 2 is not in  ( n )

12 Lecture 14: Asymptotic Growth Sorting Cost What grows? –n = the number of elements in lst How much work are the pieces? find-best: work scales as n (increases by one) delete: work scales as n (increases by one) How many times does sort evaluate find-best and delete? n Total cost: scales as n 2

13 Lecture 14: Asymptotic Growth Sorting Cost If we double the length of the list, the amount of work approximately quadruples: there are twice as many applications of find-best, and each one takes twice as long (define (sort lst cf) (if (null? lst) lst (let ((best (find-best lst cf))) (cons best (sort (delete lst best) cf))))) (define (find-best lst cf) (if (= 1 (length lst)) (car lst) (pick-better cf (car lst) (find-best (cdr lst) cf)))) The running time of this sort procedure is in Θ(n 2 )

14 Lecture 14: Asymptotic Growth Timing Sort = n 2 /500 measured times Θ(n2)Θ(n2)

15 Lecture 14: Asymptotic Growth Is our sort good enough? Takes over 1 second to sort 1000-length list. How long would it take to sort 1 million items? 1s = time to sort s ~ time to sort M is 1000 * 1000 Sorting time is n 2 so, sorting 1000 times as many items will take times as long = 1 million seconds ~ 11 days Note: there are 800 Million VISA cards in circulation. It would take 20,000 years to process a VISA transaction at this rate. Eyes by John Devor and Eric Montgomery

16 Lecture 14: Asymptotic Growth Which of these is true? Our sort procedure is too slow for VISA because its running time is in O(n 2 ) Our sort procedure is too slow for VISA because its running time is in  (n 2 ) Our sort procedure is too slow for VISA because its running time is in  (n 2 ) Knowing a running time is in O(f) tells you the running time is not worse than f. This can only be good news. It doesn’t tell you anything about how bad it is. (Lots of people and books get this wrong.)

17 Lecture 14: Asymptotic Growth Charge Read Chapter 6 and 7 of the course book PS4 is due Monday