CPSC 320: Intermediate Algorithm Design & Analysis Asymptotic Notation: (O, Ω, Θ, o, ω) Steve Wolfman 1.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

 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.
Asymptotic Notation (O, Ω,  ) s Describes the behavior of the time or space complexity for large instance characteristics s Common asymptotic functions.
Asymptotic Growth Rate
CSE 326 Asymptotic Analysis David Kaplan Dept of Computer Science & Engineering Autumn 2001.
Cutler/HeadGrowth of Functions 1 Asymptotic Growth Rate.
© 2004 Goodrich, Tamassia Sorting Lower Bound1. © 2004 Goodrich, Tamassia Sorting Lower Bound2 Comparison-Based Sorting (§ 10.3) Many sorting algorithms.
CSE 326: Data Structures Lecture #2 Analysis of Algorithms Alon Halevy Fall Quarter 2000.
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.
CS2420: Lecture 4 Vladimir Kulyukin Computer Science Department Utah State University.
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 Algorithms1 Basics -- 2 From: Data Structures and Their Algorithms, by Harry R. Lewis and Larry Denenberg (Harvard University: Harper.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (1) Asymptotic Complexity 10/28/2008 Yang Song.
DAST 2005 Week 4 – Some Helpful Material Randomized Quick Sort & Lower bound & General remarks…
Summary of Algo Analysis / Slide 1 Algorithm complexity * Bounds are for the algorithms, rather than programs n programs are just implementations of an.
Sorting Lower Bound1. 2 Comparison-Based Sorting (§ 4.4) Many sorting algorithms are comparison based. They sort by making comparisons between pairs of.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
Instructor Neelima Gupta
Asymptotic Notations Iterative Algorithms and their analysis
Lecture 2 We have given O(n 3 ), O(n 2 ), O(nlogn) algorithms for the max sub-range problem. This time, a linear time algorithm! The idea is as follows:
Mathematics Review and Asymptotic Notation
CS 3343: Analysis of Algorithms
2IL50 Data Structures Fall 2015 Lecture 2: Analysis of Algorithms.
Analysis of Algorithm Efficiency Dr. Yingwu Zhu p5-11, p16-29, p43-53, p93-96.
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
CSCI 3160 Design and Analysis of Algorithms Tutorial 1
Asymptotic Analysis-Ch. 3
CS221: Algorithms and Data Structures Lecture #4 Sorting Things Out Steve Wolfman 2014W1 1.
MCA 202: Discrete Structures Instructor Neelima Gupta
Algorithms Growth of Functions. Some Notation NNatural numbers RReal numbers N + Positive natural numbers R + Positive real numbers R * Non-negative real.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Analysis of Algorithms1 O-notation (upper bound) Asymptotic running times of algorithms are usually defined by functions whose domain are N={0, 1, 2, …}
Growth of Functions. 2 Analysis of Bubble Sort 3 Time Analysis – Best Case The array is already sorted – no swap operations are required.
Asymptotic Growth Rates  Themes  Analyzing the cost of programs  Ignoring constants and Big-Oh  Recurrence Relations & Sums  Divide and Conquer 
Algorithmic Analysis Charl du Plessis and Robert Ketteringham.
CS221: Algorithms and Data Structures Lecture #4 Sorting Things Out Steve Wolfman 2011W2 1.
David Luebke 1 1/6/2016 CS 332: Algorithms Asymptotic Performance.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Asymptotic Performance. Review: Asymptotic Performance Asymptotic performance: How does algorithm behave as the problem size gets very large? Running.
Midterm Review 1. Midterm Exam Thursday, October 15 in classroom 75 minutes Exam structure: –TRUE/FALSE questions –short questions on the topics discussed.
Spring 2015 Lecture 2: Analysis of Algorithms
1 CSC 421: Algorithm Design & Analysis Spring 2014 Complexity & lower bounds  brute force  decision trees  adversary arguments  problem reduction.
Asymptotic Analysis CSE 331. Definition of Efficiency An algorithm is efficient if, when implemented, it runs quickly on real instances Implemented where?
David Meredith Growth of Functions David Meredith
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
13 February 2016 Asymptotic Notation, Review of Functions & Summations.
Asymptotic Notation Faculty Name: Ruhi Fatima
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
Sorting Lower Bounds n Beating Them. Recap Divide and Conquer –Know how to break a problem into smaller problems, such that –Given a solution to the smaller.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
Introduction to Algorithms
CPSC 411 Design and Analysis of Algorithms
Optimal Algorithms Search and Sort.
CS 3343: Analysis of Algorithms
(2,4) Trees 11/15/2018 9:25 AM Sorting Lower Bound Sorting Lower Bound.
O-notation (upper bound)
Asymptotic Growth Rate
(2,4) Trees 12/4/2018 1:20 PM Sorting Lower Bound Sorting Lower Bound.
CS 3343: Analysis of Algorithms
Advanced Analysis of Algorithms
Chapter 2.
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
O-notation (upper bound)
CPSC 411 Design and Analysis of Algorithms
David Kauchak cs161 Summer 2009
Advanced Analysis of Algorithms
Presentation transcript:

CPSC 320: Intermediate Algorithm Design & Analysis Asymptotic Notation: (O, Ω, Θ, o, ω) Steve Wolfman 1

Analysis of Algorithms Analysis of an algorithm gives insight into how long the program runs and how much memory it uses – time complexity – space complexity Analysis can provide insight into alternative algorithms Input size is indicated by a number n (sometimes there are multiple inputs) Running time is a function of n (Z +  R + ) such as T(n) = 4n + 5 T(n) = 0.5 n log n - 2n + 7 T(n) = 2 n + n 3 + 3n But... 2 We’ll be fast and loose on the “R + ” part... If the function goes negative, let’s assume it’s actually some small positive constant.

Types of asymptotic analysis bound flavor – upper bound (O, o) – lower bound ( ,  ) – asymptotically tight (  ) analysis case – worst case (adversary) – average case – expected case – best case – “common” case – “amortized” analysis quality – loose bound (any true analysis) – tight bound (no better bound which is asymptotically different) 3

Order Notation T(n)  O(f(n)) if there are constants c and n 0 such that T(n)  c f(n) for all n  n 0 4

Big-O Practice Prove that n 2 /2 + 5n/2  O(n 2 ) Prove that n 2 /2 + 5n/2  O(n) Prove that 3 n  O(2 n ) 5

Asymptotic Analysis Hacks Eliminate low order terms – 4n + 5  4n – 0.5 n log n - 2n + 7  0.5 n log n – 2 n + n 3 + 3n  2 n Eliminate coefficients – 4n  n – 0.5 n log n  n log n – n log (n 2 ) = 2 n log n  n log n 6

Justifying the Hacks 7

More Order Notation T(n)  O(f(n)) iff there are constants c  R + and n 0  Z + such that T(n)  c f(n) for all n  n 0 T(n)   (f(n)) iff there are constants c  R + and n 0  Z + such that f(n)  c T(n) for all n  n 0 T(n)   (f(n)) iff T(n)  O(f(n)) and T(n)   (f(n)) T(n)  o(f(n)) iff for all constants c, there is a constant n 0 such that T(n) < c f(n) for all n  n 0 T(n)  ω(f(n)) iff for all constants c, there is a constant n 0 such that T(n) > c f(n) for all n  n 0 8 For my 221ers... I defined o and  blatantly wrong! Sorry 

Limits Definition of o/ ω/Θ f(n)  o(g(n)) iff f(n)  Θ(g(n)) iff for some constant 0 < c f(n)  ω(g(n)) iff 9

L’H ôpital’s Rule Reminder If or Then 10

Limits Practice Prove that 2 2 n  ω(n n ) Prove that lg n  o(n 0.5 ) 11

Complexity of Sorting Using Comparisons as a Problem Each comparison is a “choice point” in the algorithm. You can do one thing if the comparison is true and another if false. So, the whole algorithm is like a binary tree… …… sorted!z < cc < dsorted! a < da < b x < y …… yesno yesnoyesno yesnoyesno 12

Complexity of Sorting Using Comparisons as a Problem The algorithm spits out a (possibly different) sorted list at each leaf. What’s the maximum number of leaves? …… sorted!z < cc < dsorted! a < da < b x < y …… yesno yesnoyesno yesnoyesno 13

Complexity of Sorting Using Comparisons as a Problem There are n! possible permutations of a sorted list (i.e., input orders for a given set of input elements). How deep must the tree be to distinguish those input orderings? …… sorted!z < cc < dsorted! a < da < b x < y …… yesno yesnoyesno yesnoyesno 14

Complexity of Sorting Using Comparisons as a Problem If the tree is not at least lg(n!) deep, then there’s some pair of orderings I could feed the algorithm which the algorithm does not distinguish. So, it must not successfully sort one of those two orderings. …… sorted!z < cc < dsorted! a < da < b x < y …… yesno yesnoyesno yesnoyesno 15

Complexity of Sorting Using Comparisons as a Problem QED: The complexity of sorting using comparisons is  (lg (n!)) in the worst case, regardless of algorithm! In general, we can lower-bound but not upper- bound the complexity of problems. (Why not? Because I can give as crappy an algorithm as I please to solve any problem.) 16

 Practice: Find a Good Bound for lg (n!) 17

More Practice: Find Θ- Bound for lg (n!) (This isn’t tightly related to our decision tree proof, except that it shows our Ω-bound is tight.) 18

What’s Next? Divide and Conquer Algorithms Recurrence Relations CLRS Chapter 4 19

On Your Own PRACTICE PRACTICE PRACTICE with proofs about asymptotic complexity (there are many practice problems in the textbook and on old exams) 20