Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis

Similar documents
Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Analysis of Algorithms

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Data Structures and Algorithms. Analysis of Algorithms

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance

Analysis of Algorithms

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs

Analysis of Algorithms

Analysis of Algorithms

Elementary maths for GMT. Algorithm analysis Part I

LECTURE 9 Data Structures: A systematic way of organizing and accessing data. --No single data structure works well for ALL purposes.

How do we evaluate algorithms?

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming

Data Structures Lecture 8

CIS 121 Data Structures and Algorithms with Java Fall Big-Oh Notation Tuesday, September 5 (Make-up Friday, September 8)

Outline and Reading. Analysis of Algorithms 1

A graphical view of big-o notation. c*g(n) f(n) f(n) = O(g(n))

Algorithm. Counting Sort Analysis of Algorithms

9/10/2018 Algorithms & Data Structures Analysis of Algorithms. Siyuan Jiang, Sept

Big-O Analysis. Asymptotics

Big-O Analysis. Asymptotics

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS)

Homework 1 Solutions MA 522 Fall 2017

Algorithms Chapter 3 Growth of Functions

A Generalized Set Theoretic Approach for Time and Space Complexity Analysis of Algorithms and Functions

CSE 417: Algorithms and Computational Complexity

2. ALGORITHM ANALYSIS

6.854J / J Advanced Algorithms Fall 2008

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.

Lecture 1: Introduction and Strassen s Algorithm

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence

CS473-Algorithms I. Lecture 2. Asymptotic Notation. CS 473 Lecture 2 1

Exact Minimum Lower Bound Algorithm for Traveling Salesman Problem

. Written in factored form it is easy to see that the roots are 2, 2, i,

Algorithms and Data Structures

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions:

COMP Parallel Computing. PRAM (1): The PRAM model and complexity measures

Lecture 5. Counting Sort / Radix Sort

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Examples and Applications of Binary Search

Abstract Data Types (ADTs) Stacks. The Stack ADT ( 4.2) Stack Interface in Java

Algorithm Efficiency

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Heaps. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015

Data Structures and Algorithms

CS 11 C track: lecture 1

Counting the Number of Minimum Roman Dominating Functions of a Graph

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

Python Programming: An Introduction to Computer Science

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

condition w i B i S maximum u i

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0

Ones Assignment Method for Solving Traveling Salesman Problem

Practical Session 2 Constants Don t Matter!!!

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis

Algorithm Analysis. October 12, CMPE 250 Algorithm Analysis October 12, / 66

Computational Geometry

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

ANALYSIS OF ALGORITHMS

Improved Random Graph Isomorphism

Sorting in Linear Time. Data Structures and Algorithms Andrei Bulatov

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames

Lower Bounds for Sorting

Chapter 4 The Datapath

COP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen

Chapter 3. More Flow of Control. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

BACHMANN-LANDAU NOTATIONS. Lecturer: Dr. Jomar F. Rabajante IMSP, UPLB MATH 174: Numerical Analysis I 1 st Sem AY

Python Programming: An Introduction to Computer Science

UNIT 4C Iteration: Scalability & Big O. Efficiency

Algorithm Design Techniques. Divide and conquer Problem

Random Graphs and Complex Networks T

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June

Thompson s Group F (p + 1) is not Minimally Almost Convex

Math Section 2.2 Polynomial Functions

CS200: Hash Tables. Prichard Ch CS200 - Hash Tables 1

CMPT 125 Assignment 2 Solutions

Lecture 2. RTL Design Methodology. Transition from Pseudocode & Interface to a Corresponding Block Diagram

Order statistics. Order Statistics. Randomized divide-andconquer. Example. CS Spring 2006

BOOLEAN DIFFERENTIATION EQUATIONS APPLICABLE IN RECONFIGURABLE COMPUTATIONAL MEDIUM

1.8 What Comes Next? What Comes Later?

Computers and Scientific Thinking

1.2 Binomial Coefficients and Subsets

FREQUENCY ESTIMATION OF INTERNET PACKET STREAMS WITH LIMITED SPACE: UPPER AND LOWER BOUNDS

Efficient Hough transform on the FPGA using DSP slices and block RAMs

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

Chapter 24. Sorting. Objectives. 1. To study and analyze time efficiency of various sorting algorithms

CSE 2320 Notes 8: Sorting. (Last updated 10/3/18 7:16 PM) Idea: Take an unsorted (sub)array and partition into two subarrays such that.

Designing a learning system

Bezier curves. Figure 2 shows cubic Bezier curves for various control points. In a Bezier curve, only

Fast Fourier Transform (FFT) Algorithms

Today s objectives. CSE401: Introduction to Compiler Construction. What is a compiler? Administrative Details. Why study compilers?

Transcription:

Outlie ad Readig Aalysis of Algorithms Iput Algorithm Output Ruig time ( 3.) Pseudo-code ( 3.2) Coutig primitive operatios ( 3.3-3.) Asymptotic otatio ( 3.6) Asymptotic aalysis ( 3.7) Case study Aalysis of Algorithms 2 Ruig Time Experimetal Studies The ruig time of a algorithm varies with the iput ad typically grows with the iput size Average case difficult to determie We focus o the worst case ruig time Easier to aalyze Crucial to applicatios such as games, fiace ad robotics Ruig Time 2 8 6 4 2 best case average case worst case 2 3 4 Iput Size Write a program implemetig the algorithm Ru the program with iputs of varyig size ad compositio Use a method like System.curretTimeMillis() to get a accurate measure of the actual ruig time Plot the results Time (ms) 9 8 7 6 4 3 2 Iput Size Aalysis of Algorithms 3 Aalysis of Algorithms 4 Limitatios of Experimets It is ecessary to implemet the algorithm, which may be difficult Results may ot be idicative of the ruig time o other iputs ot icluded i the experimet. I order to compare two algorithms, the same hardware ad software eviromets must be used Theoretical Aalysis Uses a high-level descriptio of the algorithm istead of a implemetatio Takes ito accout all possible iputs Allows us to evaluate the speed of a algorithm idepedet of the hardware/software eviromet Aalysis of Algorithms Aalysis of Algorithms 6

Pseudocode High-level descriptio of a algorithm More structured tha Eglish prose Less detailed tha a program Preferred otatio for describig algorithms Hides program desig issues Example: fid max elemet of a array AlgorithmarrayMax(A, ) Iput array A of itegers Outputmaximum elemet of A curretmax A[] for i to do if A[i] > curretmax the curretmax A[i] retur curretmax Pseudocode Details Cotrol flow if the [else ] while do repeat util for do Idetatio replaces braces Method declaratio Algorithm method (arg [, arg ]) Iput Output Method call var.method (arg [, arg ]) Retur value returexpressio Expressios Assigmet (like = i Java) = Equality testig (like == i Java) 2 Superscripts ad other mathematical formattig allowed Aalysis of Algorithms 7 Aalysis of Algorithms 8 Primitive Operatios Coutig Primitive Operatios Basic computatios performed by a algorithm Idetifiable i pseudocode Largely idepedet from the programmig laguage Exact defiitio ot importat (we will see why later) Examples: Evaluatig a expressio Assigig a value to a variable Idexig ito a array Callig a method Returig from a method By ispectig the pseudocode, we ca determie the maximum umber of primitive operatios executed by a algorithm, as a fuctio of the iput size AlgorithmarrayMax(A, ) # operatios curretmax A[] 2 for i to do 2 + if A[i] > curretmax the 2( ) curretmax A[i] 2( ) { icremet couter i } 2( ) retur curretmax Total 7 Aalysis of Algorithms 9 Aalysis of Algorithms Estimatig Ruig Time Algorithm arraymax executes 7 primitive operatios i the worst case Defie a Time take by the fastest primitive operatio b Time take by the slowest primitive operatio Let T() be the actual worst-case ruig time of arraymax. We have a (7 ) T() b(7 ) Hece, the ruig time T() is bouded by two liear fuctios Aalysis of Algorithms Growth Rate of Ruig Time Chagig the hardware/ software eviromet Affects T() by a costat factor, but Does ot alter the growth rate of T() The liear growth rate of the ruig time T() is a itrisic property of algorithm arraymax Aalysis of Algorithms 2 2

Growth Rates Growth rates of fuctios: Liear Quadratic 2 Cubic 3 T ( ) I a log-log chart, the slope of the lie correspods to the growth rate of the fuctio E+3 E+28 Cubic E+26 E+24 Quadratic E+22 E+2 Liear E+8 E+6 E+4 E+2 E+ E+8 E+6 E+4 E+2 E+ E+ E+2 E+4 E+6 E+8 E+ Costat Factors The growth rate is ot affected by costat factors or lower-order terms Examples 2 + is a liear fuctio 2 + 8 is a quadratic fuctio T ( ) E+26 E+24 E+22 E+2 E+8 E+6 E+4 E+2 E+ E+8 E+6 E+4 E+2 E+ Quadratic Quadratic Liear Liear E+ E+2 E+4 E+6 E+8 E+ Aalysis of Algorithms 3 Aalysis of Algorithms 4 Big-Oh Notatio Give fuctios f() ad g(), we say that f() is O(g()) if there are positive costats c ad such that f() cg() for Example: 2 + is O() 2 + c (c 2) /(c 2) Pick c = 3 ad =,, 3 2+, Aalysis of Algorithms Big-Oh Notatio (cot.) Example: the fuctio 2 is ot O() 2 c c The above iequality caot be satisfied sice c must be a costat,,,,, ^2, Aalysis of Algorithms 6 Big-Oh ad Growth Rate The big-oh otatio gives a upper boud o the growth rate of a fuctio The statemet f() is O(g()) meas that the growth rate of f() is o more tha the growth rate of g() We ca use the big -Oh otatio to rak fuctios accordig to their growth rate g() grows more f() grows more Same growth f() is O(g()) No g() is O(f()) No Aalysis of Algorithms 7 Classes of Fuctios Let {g()} deote the class (set) of fuctios that are O(g()) We have {} { 2 } { 3 } { 4 } { } where the cotaimet is strict { 3 } { 2 } {} Aalysis of Algorithms 8 3

Big-Oh Rules If is f() a polyomial of degree d, the f() is O( d ), i.e.,. Drop lower-order terms 2. Drop costat factors Use the smallest possible class of fuctios Say 2 is O() istead of 2 is O( 2 ) Use the simplest expressio of the class Say 3 + is O() istead of 3 + is O(3) Aalysis of Algorithms 9 Asymptotic Algorithm Aalysis The asymptotic aalysis of a algorithm determies the ruig time i big -Oh otatio To perform the asymptotic aalysis We fid the worst-case umber of primitive operatios executed as a fuctio of the iput size We express this fuctio with big-oh otatio Example: We determie that algorithm arraymax executes at most 7 primitive operatios We say that algorithm arraymax rus i O() time Sice costat factors ad lower-order terms are evetually dropped ayhow, we ca disregard them whe coutig primitive operatios Aalysis of Algorithms 2 Computig Prefix Averages We further illustrate asymptotic aalysis with two algorithms for prefix averages The i-th prefix average of a array X is average of the first (i + ) elemets of X A[i] = (X[] + X[] + + X[i])/(i+) Computig the array A of prefix averages of aother array X has applicatios to fiacial aalysis 3 3 2 2 X A 2 3 4 6 7 Aalysis of Algorithms 2 Prefix Averages (Quadratic) The followig algorithm computes prefix averages i quadratic time by applyig the defiitio AlgorithmprefixAverages(X, ) Iput array X of itegers Output array A of prefix averages of X #operatios A ew array of itegers for i to do s X[] for j to i do + 2 + + ( ) s s + X[j] + 2 + + ( ) A[i] s / (i + ) retur A Aalysis of Algorithms 22 Arithmetic Progressio 7 The ruig time of prefixaverages is 6 O( + 2 + + ) The sum of the first 4 itegers is ( + ) / 2 There is a simple visual 3 proof of this fact 2 Thus, algorithm prefixaverages rus i O( 2 ) time 2 3 4 6 Aalysis of Algorithms 23 Prefix Averages (Liear) The followig algorithm computes prefix averages i liear time by keepig a ruig sum AlgorithmprefixAverages2(X, ) Iput array X of itegers Output array A of prefix averages of X #operatios A ew array of itegers s for i to do s s + X[i] A[i] s / (i + ) retur A Algorithm prefixaverages2 rus i O() time Aalysis of Algorithms 24 4

Asymptotic Notatio (termiology): Special classes of algorithms: logarithmic: O(log ) liear: O() quadratic: O( 2 ) polyomial: O( k ), k = expoetial: O(a ), > Relatives of the Big-Oh Ω (f()): Big Omega--asymptotic lower boud Θ (f()): Big Theta--asymptotic tight boud A table of fuctios wrt iput, assume that each primitive operatio takes oe microsecod ( secod = 6 microsecod). O(g()) log 2 log 2 2 3 2 Secod 3 2 6 9 Hour 9.3* 9 3.6* 9 9 6* 4 3 Moth Cetury.8*2 6.8* 24 2.6* 2.6* 6 4 4 9.7* 3 3.2* 4.6* 7! 9 2 7 Aalysis of Algorithms 2 Aalysis of Algorithms 26