MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2

Size: px
Start display at page:

Download "MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2"

Transcription

1 MA008 p.1/36 MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2 Dr. Markus Hagenbuchner markus@uow.edu.au.

2 MA008 p.2/36 Content of lecture 2 Examples Review data structures Data types vs. data structures. Pros and Cons (when to use what) Asymptotic notation Purpose of the notation Theoretical foundation

3 MA008 p.3/36 Data Structures reviewed Types/Structures: Basic data types (Scalars) Arrays (1-dimensional) n-dimensional arrays (matrix) Lists Trees Graphs (directed, undirected) Whiteboard exercise

4 MA008 p.4/36 Asymptotic notation Example: Assume two programs where the running time is: T 1 (n) = n 3. T 2 (n) = 100n. The former algorithm may be faster for small n. But the study on small n is not interesting. Why?

5 MA008 p.5/36 Asymptotic notation Example: Assuming one million operations per second. n T 1 (n) T 2 (n) T 1 (n)/t 2 (n) sec sec sec 0.01 sec 100 1, sec 0.1 sec 10, , days 1 sec 1, 000, 000

6 MA008 p.6/36 Asymptotic notation Studying behavior for large n is interesting because: Almost all commercially practical problems involve large n Impact of large n is much more pronounced than for small n (when n is small the computational complexity doesn t really matter). Constants are almost always neglected since such factors do not contribute significantly when n is large (e.g. lim n ).

7 MA008 p.7/36 Asymptotic notation Essential to know the answer to: Q: What is n when processing: A set of numbers, set of vectors a or sequences b, iterative/recursive processing of data? Q: What is a basic operator? Is output a basic operator? a Fixed dimensional b Finite length sequences.

8 MA008 p.8/36 Asymptotic Notation Is the representation of running times of algorithms in a simple form by considering its fastest growing term and asymptotic insignificant factors.

9 MA008 p.9/36 Asymptotic Notation Let f(n) and g(n) be two functions, which are assumed to be positive. Suppose we want to assert that f(n) and g(n) grow at roughly the same rates for large n (ignoring constant factors). This would be equivalent to saying lim n f(n) g(n) = c, where c is some non-zero numerical constant.

10 MA008 p.10/36 Asymptotic Notation In asymptotic notation we write f(n) O(g(n)). Intuitively, it means that f(n) and g(n) are asymptotically equivalent. Indeed, lim n f(n) g(n) = c lim n g(n) f(n) = 1/c, provided c 0,.

11 MA008 p.11/36 Asymptotic Notation To compare the order of growth of an algorithm this can formally be distinguished by the three notations: O (big Oh), Θ (big Theta), and Ω (big Omega), where Ω stands for the set of all functions with a larger or same order of growth Θ is for the set of functions that have the same order of growth, and O is the set of all functions with a smaller or same order of growth.

12 MA008 p.12/36 Asymptotic Notation Suppose we want to assert that f(n) does not grow significantly faster than g(n). Then the ratio f(n)/g(n) should either approach a constant (they are equivalent) or 0 (if g(n) grows faster than f(n)). In this case we say f(n) O(g(n)). Common definitions: Asymptotic Form Relationship Definition f(n) Θ(g(n)) f(n) g(n) 0 < lim n f(n) g(n) <. f(n) O(g(n)) f(n) g(n) 0 lim n f(n) g(n) <. f(n) Ω(g(n)) f(n) g(n) 0 < lim n f(n) g(n).

13 MA008 p.13/36 Asymptotic Notation An example: Let T(n) = (n 3 + 3n 2 + 2n)/6. Then T(n) Θ(n 3 ). Since lim n T(n) n 3 = lim n (n 3 + 3n 2 + 2n)/6 n 3 = lim n ( n + 1 3n 2) = 1 6, and 0 < 1/6 <. (Note that it also follows that T(n) O(n 3 ) and T(n) Ω(n 3 )).

14 MA008 p.14/36 Asymptotic Notation: Rules The following rules are useful when dealing with asymptotic comparisons. L Hôpital s rule: If f(n) and g(n) both approach 0 or both approach in the limit, then lim n f(n) g(n) = lim n f (n) g (n), where f (n) and g (n) denote the derivatives of f and g relative to n.

15 MA008 p.15/36 Asymptotic Notation Constants: Multiplicative and additive constants are ignored. When constants appear in exponents or as the base of an exponential, they are significant. Thus, n 2 O(n 3 ) and 2 n O(3 n ) (Can you prove it?). Logarithm base: Logarithms in different bases differ only by a constant factor, thus log 2 n log 3 n. Thus, the logarithm bases inside asymptotic notations are often ignored, as in O(n log n).

16 MA008 p.16/36 Asymptotic Notation Properties of Logarithms and Summations: Since logarithms/summations occur frequently in the analysis of algorithms, we briefly review the properties of logarithms/summations as follows.

17 MA008 p.17/36 Asymptotic Notation: Review of log Logs and powers: Remember that you call pull an exponent out of a logarithm as a multiplicative factor. Thus n log 2 (n 2 ) = 2n log 2 n n log n. Exponents and logs: Remember that exponentials and logs cancel one another. Thus 2 log 2 n = n.

18 MA008 p.18/36 Asymptotic Notation: Review continued Logs and polynomials: For any a,b 0, (log n) a O(n b ). This simply says that logs grow more slowly than any polynomial. Polynomials and exponentials: For any a 0,b > 1,n a O(b n ). This simply says that polynomials grow more slowly than any exponential.

19 MA008 p.19/36 Asymptotic Notation: Further properties of log Let x,y > 0 and a,b > 1. Then the following properties apply: 1. log b (xy) = log b x + log b y 2. log b (x/y) = log b x log b y 3. log b (x i ) = i log b x 4. log b x = 1/ log x b 5. log b x = log b a log a x 6. x log b y = y log b x.

20 MA008 p.20/36 Asymptotic Notation Exercise: Prove property 5: (log b x = log b a log a x).

21 MA008 p.21/36 Asymptotic Notation Property 5 explains why we can talk of logarithmic growth without reference to the base. Suppose f(n) = log b n and g(n) = log a n. Then f(n) = log b a g(n). The factor log b a is a constant (independent of n). Hence f(n) is Θ(g(n)) and vice versa. Thus, we often say a function is Θ(log n) without specifying the base, since the base does not affect the rate of growth. Suppose f(n) = b log a n. Then from property 6 we can rewrite f(n) = n log a b, which is a more meaningful form.

22 MA008 p.22/36 Asymptotic Notation: Summations Constant Series: For integers a and b, b 1 = i=a { (b a + 1) if b a 1 0 otherwise. Proof:

23 Asymptotic Notation: Summations Constant Series: For integers a and b, b 1 = i=a { (b a + 1) if b a 1 0 otherwise. Proof: b i=a 1 = b 1 i=0 a 1 i=0 1 = }{{} b+1 times }{{} a times = b + 1 a MA008 p.22/36

24 MA008 p.23/36 Asymptotic Notation: Arithmetic Series Arithmetic Series: For n 0, n i=0 i = n = n(n + 1). 2 That is Θ(n 2 ). Proof:

25 Asymptotic Notation: Arithmetic Series Arithmetic Series: For n 0, n i=0 i = n = n(n + 1). 2 That is Θ(n 2 ). Proof: n i=0 i + 0 i=n i = 2 n i i=0 = (n + 1) + (n + 1) + + (n + 1) }{{} n times = (n + 1)n MA008 p.23/36

26 MA008 p.24/36 Asymptotic Notation: Geometric Series Geometric Series: Let x 1 be any constant (independent of n), then for n 0, n i=0 x i = 1 + x + x x n = xn+1 1 x 1. If 0 < x < 1 then this is Θ(1). If x > 1, then this is Θ(x n ), that is, the entire sum is proportional to the last element of the series. Can you proof it?

27 MA008 p.25/36 Asymptotic Notation: Quadratic Series Quadratic Series: For n 0, n i=0 i 2 = n 2 = 2n3 + 3n 2 + n. 6

28 MA008 p.26/36 Asymptotic Notation: Summations Linear-geometric Series: This arises in some algorithms based on trees and recursion. Let x 1 be any constant, then for n 0, n 1 i=0 ix i = x + 2x 2 + 3x nx n = (n 1)x(n+1) nx n + x (x 1) 2. (What happens in the case where x = 1?)

29 MA008 p.27/36 Asymptotic Notation: Summations Harmonic Series: This arises often in probabilistic analyses of algorithms. It does not have an exact closed form of solution, but is can be closely approximated. For n 0, H n = n i=1 1 i = n ln n.

30 MA008 p.28/36 Asymptotic Notation: Summations Summations with general bounds: When a summation does not start at the 1 or 0, you can just split it up into the difference of two summations. For example, for 1 a b b f(i) = b f(i) a 1 f(i). i=a i=0 i=0

31 MA008 p.29/36 Approximate using integrals: Integration and summation are closely related. (Integration is in some sense a continuous form of summation.) Let f(x) be any monotonically increasing function (the function increases as x increases). n 0 f(x)dx n i=1 f(i) n+1 1 f(x)dx.

32 MA008 p.30/36 Asymptotic Notation: An example Let us consider a simple example. Let A[1..4n] be some array. We are going to run the following algorithm. FOR i = n TO 2n DO{ } FOR j = 1 TO i DO{ IF (A[j] <= A[2j]) OUTPUT hello ; } Question: In the worst case, how many times is the hello line printed as a function of n?

33 Asymptotic Notation: Example Worst case: The elements of A are in ascending order if statement can always be true. Let T(n) be the number of outputs. Then the nested summation is expressed as: T(n) = 2n i 1. i=n j=1 The 1 is for one output operation. Solving these from the inside out, we see that the last summation is a constant sum, and hence T(n) = 2n (i 1 + 1) = 2n i. i=n i=n MA008 p.31/36

34 MA008 p.32/36 Asymptotic Notation This is just an arithmetic series, with general bounds, which we can break into the difference of two arithmetic series, starting from 0. T(n) = = 2n i=0 i n 1 i=0 2n(2n + 1) 2 i n(n 1) 2 = (4n2 + 2n) (n 2 n) 2 = 3 2 (n2 + n) Θ(n 2 ).

35 MA008 p.33/36 Exercise 1 Indicate whether g(n) f(n), g(n) f(n), g(n) f(n). g(n) = (n(n + 1) and f(n) = 2000n 2 g(n) = log 2 (n) and f(n) = log(n) g(n) = 2 2 n and f(n) = 2 n g(n) = (n 1)! and f(n) = n! g(n) = 100n 2 and f(n) = 0.01n 3

36 MA008 p.34/36 Exercise 2 Sashi, the inventor of the game chess, was offered a reward of his own choosing. Sashi asked for: a single grain of rice on the first square of the chess board, 2 grains on the second square, 4 grains on the 3rd square, 8 grains on the 4th, etc. until all 64 squares are filled. How much rise did Sashi ask for?

37 MA008 p.35/36 Exercise 2 (answer) Number of rice grains: 64 i=1 2i 1 = 63 j=0 2i Apply geometric series: = Assuming that one rice grain occupies 3mm 3. Then the total volume of rice would be mm 2 = km 2 This is approx 1/10 of the earth s volume!

38 MA008 p.36/36 Coming up next week Analysis of Algorithms: Techniques Case studies

Data Structures and Algorithms. Asymptotic notation

Data Structures and Algorithms. Asymptotic notation Data Structures and Algorithms Asymptotic notation Estimating Running Time Algorithm arraymax executes 7n 1 primitive operations in the worst case. Define: a = Time taken by the fastest primitive operation

More information

Asymptotic Notation. such that t(n) cf(n) for all n n 0. for some positive real constant c and integer threshold n 0

Asymptotic Notation. such that t(n) cf(n) for all n n 0. for some positive real constant c and integer threshold n 0 Asymptotic Notation Asymptotic notation deals with the behaviour of a function in the limit, that is, for sufficiently large values of its parameter. Often, when analysing the run time of an algorithm,

More information

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency Lecture 2 Fundamentals of the Analysis of Algorithm Efficiency 1 Lecture Contents 1. Analysis Framework 2. Asymptotic Notations and Basic Efficiency Classes 3. Mathematical Analysis of Nonrecursive Algorithms

More information

Computational Complexity

Computational Complexity Computational Complexity S. V. N. Vishwanathan, Pinar Yanardag January 8, 016 1 Computational Complexity: What, Why, and How? Intuitively an algorithm is a well defined computational procedure that takes

More information

Growth of Functions (CLRS 2.3,3)

Growth of Functions (CLRS 2.3,3) Growth of Functions (CLRS 2.3,3) 1 Review Last time we discussed running time of algorithms and introduced the RAM model of computation. Best-case running time: the shortest running time for any input

More information

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

More information

CS 4407 Algorithms Lecture 2: Growth Functions

CS 4407 Algorithms Lecture 2: Growth Functions CS 4407 Algorithms Lecture 2: Growth Functions Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline Growth Functions Mathematical specification of growth functions

More information

Analysis of Algorithms

Analysis of Algorithms October 1, 2015 Analysis of Algorithms CS 141, Fall 2015 1 Analysis of Algorithms: Issues Correctness/Optimality Running time ( time complexity ) Memory requirements ( space complexity ) Power I/O utilization

More information

CIS 121 Data Structures and Algorithms with Java Spring Big-Oh Notation Monday, January 22/Tuesday, January 23

CIS 121 Data Structures and Algorithms with Java Spring Big-Oh Notation Monday, January 22/Tuesday, January 23 CIS 11 Data Structures and Algorithms with Java Spring 018 Big-Oh Notation Monday, January /Tuesday, January 3 Learning Goals Review Big-Oh and learn big/small omega/theta notations Discuss running time

More information

3.1 Asymptotic notation

3.1 Asymptotic notation 3.1 Asymptotic notation The notations we use to describe the asymptotic running time of an algorithm are defined in terms of functions whose domains are the set of natural numbers N = {0, 1, 2,... Such

More information

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu Analysis of Algorithm Efficiency Dr. Yingwu Zhu Measure Algorithm Efficiency Time efficiency How fast the algorithm runs; amount of time required to accomplish the task Our focus! Space efficiency Amount

More information

The Time Complexity of an Algorithm

The Time Complexity of an Algorithm Analysis of Algorithms The Time Complexity of an Algorithm Specifies how the running time depends on the size of the input. Purpose To estimate how long a program will run. To estimate the largest input

More information

Principles of Algorithm Analysis

Principles of Algorithm Analysis C H A P T E R 3 Principles of Algorithm Analysis 3.1 Computer Programs The design of computer programs requires:- 1. An algorithm that is easy to understand, code and debug. This is the concern of software

More information

The Time Complexity of an Algorithm

The Time Complexity of an Algorithm CSE 3101Z Design and Analysis of Algorithms The Time Complexity of an Algorithm Specifies how the running time depends on the size of the input. Purpose To estimate how long a program will run. To estimate

More information

CSC Design and Analysis of Algorithms. Lecture 1

CSC Design and Analysis of Algorithms. Lecture 1 CSC 8301- Design and Analysis of Algorithms Lecture 1 Introduction Analysis framework and asymptotic notations What is an algorithm? An algorithm is a finite sequence of unambiguous instructions for solving

More information

Ch01. Analysis of Algorithms

Ch01. Analysis of Algorithms Ch01. Analysis of Algorithms Input Algorithm Output Acknowledgement: Parts of slides in this presentation come from the materials accompanying the textbook Algorithm Design and Applications, by M. T. Goodrich

More information

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count Types of formulas for basic operation count Exact formula e.g., C(n) = n(n-1)/2 Algorithms, Design and Analysis Big-Oh analysis, Brute Force, Divide and conquer intro Formula indicating order of growth

More information

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3 MA008 p.1/37 MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3 Dr. Markus Hagenbuchner markus@uow.edu.au. MA008 p.2/37 Exercise 1 (from LN 2) Asymptotic Notation When constants appear in exponents

More information

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2 1 Faculty of Mathematics Waterloo, Ontario Centre for Education in Mathematics and Computing Grade 11/12 Math Circles Fall 2014 - Nov. 5 Recurrences, Part 2 Running time of algorithms In computer science,

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 4 - Jan. 10, 2018 CLRS 1.1, 1.2, 2.2, 3.1, 4.3, 4.5 University of Manitoba Picture is from the cover of the textbook CLRS. 1 /

More information

More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018

More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018 CS 61B More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018 Here is a review of some formulas that you will find useful when doing asymptotic analysis. ˆ N i=1 i = 1 + 2 + 3 + 4 + + N = N(N+1)

More information

Asymptotic Analysis of Algorithms. Chapter 4

Asymptotic Analysis of Algorithms. Chapter 4 Asymptotic Analysis of Algorithms Chapter 4 Overview Motivation Definition of Running Time Classifying Running Time Asymptotic Notation & Proving Bounds Algorithm Complexity vs Problem Complexity Overview

More information

How many hours would you estimate that you spent on this assignment?

How many hours would you estimate that you spent on this assignment? The first page of your homework submission must be a cover sheet answering the following questions. Do not leave it until the last minute; it s fine to fill out the cover sheet before you have completely

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 4 - Jan. 14, 2019 CLRS 1.1, 1.2, 2.2, 3.1, 4.3, 4.5 University of Manitoba Picture is from the cover of the textbook CLRS. COMP

More information

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013 /4/3 Administrative Big O David Kauchak cs3 Spring 3 l Assignment : how d it go? l Assignment : out soon l CLRS code? l Videos Insertion-sort Insertion-sort Does it terminate? /4/3 Insertion-sort Loop

More information

CS 380 ALGORITHM DESIGN AND ANALYSIS

CS 380 ALGORITHM DESIGN AND ANALYSIS CS 380 ALGORITHM DESIGN AND ANALYSIS Lecture 2: Asymptotic Analysis, Insertion Sort Text Reference: Chapters 2, 3 Space and Time Complexity For a given problem, may be a variety of algorithms that you

More information

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation: CS 124 Section #1 Big-Oh, the Master Theorem, and MergeSort 1/29/2018 1 Big-Oh Notation 1.1 Definition Big-Oh notation is a way to describe the rate of growth of functions. In CS, we use it to describe

More information

The Growth of Functions and Big-O Notation

The Growth of Functions and Big-O Notation The Growth of Functions and Big-O Notation Big-O Notation Big-O notation allows us to describe the aymptotic growth of a function without concern for i) constant multiplicative factors, and ii) lower-order

More information

CSE 421: Intro Algorithms. 2: Analysis. Winter 2012 Larry Ruzzo

CSE 421: Intro Algorithms. 2: Analysis. Winter 2012 Larry Ruzzo CSE 421: Intro Algorithms 2: Analysis Winter 2012 Larry Ruzzo 1 Efficiency Our correct TSP algorithm was incredibly slow Basically slow no matter what computer you have We want a general theory of efficiency

More information

Lecture 2: Asymptotic Notation CSCI Algorithms I

Lecture 2: Asymptotic Notation CSCI Algorithms I Lecture 2: Asymptotic Notation CSCI 700 - Algorithms I Andrew Rosenberg September 2, 2010 Last Time Review Insertion Sort Analysis of Runtime Proof of Correctness Today Asymptotic Notation Its use in analyzing

More information

CS Non-recursive and Recursive Algorithm Analysis

CS Non-recursive and Recursive Algorithm Analysis CS483-04 Non-recursive and Recursive Algorithm Analysis Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 4:30pm - 5:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/

More information

COMP 9024, Class notes, 11s2, Class 1

COMP 9024, Class notes, 11s2, Class 1 COMP 90, Class notes, 11s, Class 1 John Plaice Sun Jul 31 1::5 EST 011 In this course, you will need to know a bit of mathematics. We cover in today s lecture the basics. Some of this material is covered

More information

CSED233: Data Structures (2017F) Lecture4: Analysis of Algorithms

CSED233: Data Structures (2017F) Lecture4: Analysis of Algorithms (2017F) Lecture4: Analysis of Algorithms Daijin Kim CSE, POSTECH dkim@postech.ac.kr Running Time Most algorithms transform input objects into output objects. The running time of an algorithm typically

More information

Ch 01. Analysis of Algorithms

Ch 01. Analysis of Algorithms Ch 01. Analysis of Algorithms Input Algorithm Output Acknowledgement: Parts of slides in this presentation come from the materials accompanying the textbook Algorithm Design and Applications, by M. T.

More information

Lecture 2. More Algorithm Analysis, Math and MCSS By: Sarah Buchanan

Lecture 2. More Algorithm Analysis, Math and MCSS By: Sarah Buchanan Lecture 2 More Algorithm Analysis, Math and MCSS By: Sarah Buchanan Announcements Assignment #1 is posted online It is directly related to MCSS which we will be talking about today or Monday. There are

More information

Asymptotic Analysis Cont'd

Asymptotic Analysis Cont'd Cont'd Carlos Moreno cmoreno @ uwaterloo.ca EIT-4103 https://ece.uwaterloo.ca/~cmoreno/ece250 Announcements We have class this Wednesday, Jan 18 at 12:30 That is, we have two sessions this Wednesday: at

More information

Data Structures and Algorithms CSE 465

Data Structures and Algorithms CSE 465 Data Structures and Algorithms CSE 465 LECTURE 3 Asymptotic Notation O-, Ω-, Θ-, o-, ω-notation Divide and Conquer Merge Sort Binary Search Sofya Raskhodnikova and Adam Smith /5/0 Review Questions If input

More information

EECS 477: Introduction to algorithms. Lecture 5

EECS 477: Introduction to algorithms. Lecture 5 EECS 477: Introduction to algorithms. Lecture 5 Prof. Igor Guskov guskov@eecs.umich.edu September 19, 2002 1 Lecture outline Asymptotic notation: applies to worst, best, average case performance, amortized

More information

P, NP, NP-Complete, and NPhard

P, NP, NP-Complete, and NPhard P, NP, NP-Complete, and NPhard Problems Zhenjiang Li 21/09/2011 Outline Algorithm time complicity P and NP problems NP-Complete and NP-Hard problems Algorithm time complicity Outline What is this course

More information

Cpt S 223. School of EECS, WSU

Cpt S 223. School of EECS, WSU Algorithm Analysis 1 Purpose Why bother analyzing code; isn t getting it to work enough? Estimate time and memory in the average case and worst case Identify bottlenecks, i.e., where to reduce time Compare

More information

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation: CS 124 Section #1 Big-Oh, the Master Theorem, and MergeSort 1/29/2018 1 Big-Oh Notation 1.1 Definition Big-Oh notation is a way to describe the rate of growth of functions. In CS, we use it to describe

More information

Analysis of Algorithms

Analysis of Algorithms Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Analysis of Algorithms Input Algorithm Analysis

More information

COMPUTER ALGORITHMS. Athasit Surarerks.

COMPUTER ALGORITHMS. Athasit Surarerks. COMPUTER ALGORITHMS Athasit Surarerks. Introduction EUCLID s GAME Two players move in turn. On each move, a player has to write on the board a positive integer equal to the different from two numbers already

More information

COMP 355 Advanced Algorithms

COMP 355 Advanced Algorithms COMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background 1 Polynomial Running Time Brute force. For many non-trivial problems, there is a natural brute force search algorithm that

More information

Time complexity analysis

Time complexity analysis Time complexity analysis Let s start with selection sort C. Seshadhri University of California, Santa Cruz sesh@ucsc.edu March 30, 2016 C. Seshadhri (UCSC) CMPS101 1 / 40 Sorting Sorting Input An array

More information

data structures and algorithms lecture 2

data structures and algorithms lecture 2 data structures and algorithms 2018 09 06 lecture 2 recall: insertion sort Algorithm insertionsort(a, n): for j := 2 to n do key := A[j] i := j 1 while i 1 and A[i] > key do A[i + 1] := A[i] i := i 1 A[i

More information

Running Time Evaluation

Running Time Evaluation Running Time Evaluation Quadratic Vs. Linear Time Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 19 1 Running time 2 Examples 3 Big-Oh, Big-Omega, and Big-Theta Tools 4 Time

More information

Module 1: Analyzing the Efficiency of Algorithms

Module 1: Analyzing the Efficiency of Algorithms Module 1: Analyzing the Efficiency of Algorithms Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Based

More information

COMP 382: Reasoning about algorithms

COMP 382: Reasoning about algorithms Fall 2014 Unit 4: Basics of complexity analysis Correctness and efficiency So far, we have talked about correctness and termination of algorithms What about efficiency? Running time of an algorithm For

More information

with the size of the input in the limit, as the size of the misused.

with the size of the input in the limit, as the size of the misused. Chapter 3. Growth of Functions Outline Study the asymptotic efficiency of algorithms Give several standard methods for simplifying the asymptotic analysis of algorithms Present several notational conventions

More information

Asymptotic Analysis 1

Asymptotic Analysis 1 Asymptotic Analysis 1 Last week, we discussed how to present algorithms using pseudocode. For example, we looked at an algorithm for singing the annoying song 99 Bottles of Beer on the Wall for arbitrary

More information

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Xi Chen Columbia University We continue with two more asymptotic notation: o( ) and ω( ). Let f (n) and g(n) are functions that map

More information

COMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background

COMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background COMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background 1 Polynomial Time Brute force. For many non-trivial problems, there is a natural brute force search algorithm that checks every

More information

Asymptotic Analysis. Thomas A. Anastasio. January 7, 2004

Asymptotic Analysis. Thomas A. Anastasio. January 7, 2004 Asymptotic Analysis Thomas A. Anastasio January 7, 004 1 Introduction As a programmer, you often have a choice of data structures and algorithms. Choosing the best one for a particular job involves, among

More information

CS473 - Algorithms I

CS473 - Algorithms I CS473 - Algorithms I Lecture 2 Asymptotic Notation 1 O-notation: Asymptotic upper bound f(n) = O(g(n)) if positive constants c, n 0 such that 0 f(n) cg(n), n n 0 f(n) = O(g(n)) cg(n) f(n) Asymptotic running

More information

Algorithms Design & Analysis. Analysis of Algorithm

Algorithms Design & Analysis. Analysis of Algorithm Algorithms Design & Analysis Analysis of Algorithm Review Internship Stable Matching Algorithm 2 Outline Time complexity Computation model Asymptotic notions Recurrence Master theorem 3 The problem of

More information

Lecture 1: Asymptotic Complexity. 1 These slides include material originally prepared by Dr.Ron Cytron, Dr. Jeremy Buhler, and Dr. Steve Cole.

Lecture 1: Asymptotic Complexity. 1 These slides include material originally prepared by Dr.Ron Cytron, Dr. Jeremy Buhler, and Dr. Steve Cole. Lecture 1: Asymptotic Complexity 1 These slides include material originally prepared by Dr.Ron Cytron, Dr. Jeremy Buhler, and Dr. Steve Cole. Announcements TA office hours officially start this week see

More information

CS 310 Advanced Data Structures and Algorithms

CS 310 Advanced Data Structures and Algorithms CS 310 Advanced Data Structures and Algorithms Runtime Analysis May 31, 2017 Tong Wang UMass Boston CS 310 May 31, 2017 1 / 37 Topics Weiss chapter 5 What is algorithm analysis Big O, big, big notations

More information

CSE 417: Algorithms and Computational Complexity

CSE 417: Algorithms and Computational Complexity CSE 417: Algorithms and Computational Complexity Lecture 2: Analysis Larry Ruzzo 1 Why big-o: measuring algorithm efficiency outline What s big-o: definition and related concepts Reasoning with big-o:

More information

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 3. Θ Notation. Comparing Algorithms

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 3. Θ Notation. Comparing Algorithms Taking Stock IE170: Algorithms in Systems Engineering: Lecture 3 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University January 19, 2007 Last Time Lots of funky math Playing

More information

Big O Notation. P. Danziger

Big O Notation. P. Danziger 1 Comparing Algorithms We have seen that in many cases we would like to compare two algorithms. Generally, the efficiency of an algorithm can be guaged by how long it takes to run as a function of the

More information

Data Structures and Algorithms Running time and growth functions January 18, 2018

Data Structures and Algorithms Running time and growth functions January 18, 2018 Data Structures and Algorithms Running time and growth functions January 18, 2018 Measuring Running Time of Algorithms One way to measure the running time of an algorithm is to implement it and then study

More information

Written Homework #1: Analysis of Algorithms

Written Homework #1: Analysis of Algorithms Written Homework #1: Analysis of Algorithms CIS 121 Fall 2016 cis121-16fa-staff@googlegroups.com Due: Thursday, September 15th, 2015 before 10:30am (You must submit your homework online via Canvas. A paper

More information

i=1 i B[i] B[i] + A[i, j]; c n for j n downto i + 1 do c n i=1 (n i) C[i] C[i] + A[i, j]; c n

i=1 i B[i] B[i] + A[i, j]; c n for j n downto i + 1 do c n i=1 (n i) C[i] C[i] + A[i, j]; c n Fundamental Algorithms Homework #1 Set on June 25, 2009 Due on July 2, 2009 Problem 1. [15 pts] Analyze the worst-case time complexity of the following algorithms,and give tight bounds using the Theta

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 3: Growth of Functions (slides enhanced by N. Adlai A. DePano) Overview Order of growth of functions provides a simple

More information

Analysis of Algorithms Review

Analysis of Algorithms Review COMP171 Fall 2005 Analysis of Algorithms Review Adapted from Notes of S. Sarkar of UPenn, Skiena of Stony Brook, etc. Introduction to Analysis of Algorithms / Slide 2 Outline Why Does Growth Rate Matter?

More information

Defining Efficiency. 2: Analysis. Efficiency. Measuring efficiency. CSE 421: Intro Algorithms. Summer 2007 Larry Ruzzo

Defining Efficiency. 2: Analysis. Efficiency. Measuring efficiency. CSE 421: Intro Algorithms. Summer 2007 Larry Ruzzo CSE 421: Intro Algorithms 2: Analysis Summer 2007 Larry Ruzzo Defining Efficiency Runs fast on typical real problem instances Pro: sensible, bottom-line-oriented Con: moving target (diff computers, compilers,

More information

Algorithms and Their Complexity

Algorithms and Their Complexity CSCE 222 Discrete Structures for Computing David Kebo Houngninou Algorithms and Their Complexity Chapter 3 Algorithm An algorithm is a finite sequence of steps that solves a problem. Computational complexity

More information

Big-O Notation and Complexity Analysis

Big-O Notation and Complexity Analysis Big-O Notation and Complexity Analysis Jonathan Backer backer@cs.ubc.ca Department of Computer Science University of British Columbia May 28, 2007 Problems Reading: CLRS: Growth of Functions 3 GT: Algorithm

More information

Algorithms, CSE, OSU. Introduction, complexity of algorithms, asymptotic growth of functions. Instructor: Anastasios Sidiropoulos

Algorithms, CSE, OSU. Introduction, complexity of algorithms, asymptotic growth of functions. Instructor: Anastasios Sidiropoulos 6331 - Algorithms, CSE, OSU Introduction, complexity of algorithms, asymptotic growth of functions Instructor: Anastasios Sidiropoulos Why algorithms? Algorithms are at the core of Computer Science Why

More information

Analysis of Algorithms

Analysis of Algorithms Analysis of Algorithms Section 4.3 Prof. Nathan Wodarz Math 209 - Fall 2008 Contents 1 Analysis of Algorithms 2 1.1 Analysis of Algorithms....................... 2 2 Complexity Analysis 4 2.1 Notation

More information

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

More information

2. ALGORITHM ANALYSIS

2. ALGORITHM ANALYSIS 2. ALGORITHM ANALYSIS computational tractability asymptotic order of growth survey of common running times Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

1 + lim. n n+1. f(x) = x + 1, x 1. and we check that f is increasing, instead. Using the quotient rule, we easily find that. 1 (x + 1) 1 x (x + 1) 2 =

1 + lim. n n+1. f(x) = x + 1, x 1. and we check that f is increasing, instead. Using the quotient rule, we easily find that. 1 (x + 1) 1 x (x + 1) 2 = Chapter 5 Sequences and series 5. Sequences Definition 5. (Sequence). A sequence is a function which is defined on the set N of natural numbers. Since such a function is uniquely determined by its values

More information

Lecture 10: Big-Oh. Doina Precup With many thanks to Prakash Panagaden and Mathieu Blanchette. January 27, 2014

Lecture 10: Big-Oh. Doina Precup With many thanks to Prakash Panagaden and Mathieu Blanchette. January 27, 2014 Lecture 10: Big-Oh Doina Precup With many thanks to Prakash Panagaden and Mathieu Blanchette January 27, 2014 So far we have talked about O() informally, as a way of capturing the worst-case computation

More information

Analysis of Algorithms

Analysis of Algorithms September 29, 2017 Analysis of Algorithms CS 141, Fall 2017 1 Analysis of Algorithms: Issues Correctness/Optimality Running time ( time complexity ) Memory requirements ( space complexity ) Power I/O utilization

More information

Computer Algorithms CISC4080 CIS, Fordham Univ. Outline. Last class. Instructor: X. Zhang Lecture 2

Computer Algorithms CISC4080 CIS, Fordham Univ. Outline. Last class. Instructor: X. Zhang Lecture 2 Computer Algorithms CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Lecture 2 Outline Introduction to algorithm analysis: fibonacci seq calculation counting number of computer steps recursive formula

More information

Computer Algorithms CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Lecture 2

Computer Algorithms CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Lecture 2 Computer Algorithms CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Lecture 2 Outline Introduction to algorithm analysis: fibonacci seq calculation counting number of computer steps recursive formula

More information

Announcements. CompSci 230 Discrete Math for Computer Science. The Growth of Functions. Section 3.2

Announcements. CompSci 230 Discrete Math for Computer Science. The Growth of Functions. Section 3.2 CompSci 230 Discrete Math for Computer Science Announcements Read Chap. 3.1-3.3 No recitation Friday, Oct 11 or Mon Oct 14 October 8, 2013 Prof. Rodger Section 3.2 Big-O Notation Big-O Estimates for Important

More information

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

Lecture 1: Asymptotics, Recurrences, Elementary Sorting Lecture 1: Asymptotics, Recurrences, Elementary Sorting Instructor: Outline 1 Introduction to Asymptotic Analysis Rate of growth of functions Comparing and bounding functions: O, Θ, Ω Specifying running

More information

Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc.

Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc. Algorithms Analysis Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc. Algorithms analysis tends to focus on time: Techniques for measuring

More information

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2019

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2019 CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2019 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis

More information

Asymptotic Analysis. Slides by Carl Kingsford. Jan. 27, AD Chapter 2

Asymptotic Analysis. Slides by Carl Kingsford. Jan. 27, AD Chapter 2 Asymptotic Analysis Slides by Carl Kingsford Jan. 27, 2014 AD Chapter 2 Independent Set Definition (Independent Set). Given a graph G = (V, E) an independent set is a set S V if no two nodes in S are joined

More information

Asymptotic Algorithm Analysis & Sorting

Asymptotic Algorithm Analysis & Sorting Asymptotic Algorithm Analysis & Sorting (Version of 5th March 2010) (Based on original slides by John Hamer and Yves Deville) We can analyse an algorithm without needing to run it, and in so doing we can

More information

Reading 10 : Asymptotic Analysis

Reading 10 : Asymptotic Analysis CS/Math 240: Introduction to Discrete Mathematics Fall 201 Instructor: Beck Hasti and Gautam Prakriya Reading 10 : Asymptotic Analysis In the last reading, we analyzed the running times of various algorithms.

More information

CIS 121. Analysis of Algorithms & Computational Complexity. Slides based on materials provided by Mary Wootters (Stanford University)

CIS 121. Analysis of Algorithms & Computational Complexity. Slides based on materials provided by Mary Wootters (Stanford University) CIS 121 Analysis of Algorithms & Computational Complexity Slides based on materials provided by Mary Wootters (Stanford University) Today Sorting: InsertionSort vs MergeSort Analyzing the correctness of

More information

282 Math Preview. Chris Brown. September 8, Why This? 2. 2 Logarithms Basic Identities Basic Consequences...

282 Math Preview. Chris Brown. September 8, Why This? 2. 2 Logarithms Basic Identities Basic Consequences... 282 Math Preview Chris Brown September 8, 2005 Contents Why This? 2 2 Logarithms 2 2. Basic Identities.................................... 2 2.2 Basic Consequences.................................. 3 3

More information

Lecture 3. Big-O notation, more recurrences!!

Lecture 3. Big-O notation, more recurrences!! Lecture 3 Big-O notation, more recurrences!! Announcements! HW1 is posted! (Due Friday) See Piazza for a list of HW clarifications First recitation section was this morning, there s another tomorrow (same

More information

Data Structures and Algorithms Chapter 2

Data Structures and Algorithms Chapter 2 1 Data Structures and Algorithms Chapter 2 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples

More information

Analysis of Algorithms - Using Asymptotic Bounds -

Analysis of Algorithms - Using Asymptotic Bounds - Analysis of Algorithms - Using Asymptotic Bounds - Andreas Ermedahl MRTC (Mälardalens Real-Time Research Center) andreas.ermedahl@mdh.se Autumn 004 Rehersal: Asymptotic bounds Gives running time bounds

More information

Recursion. Computational complexity

Recursion. Computational complexity List. Babes-Bolyai University arthur@cs.ubbcluj.ro Overview List 1 2 List Second Laboratory Test List Will take place week 12, during the laboratory You will receive one problem statement, from what was

More information

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018 CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2018 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis

More information

Module 1: Analyzing the Efficiency of Algorithms

Module 1: Analyzing the Efficiency of Algorithms Module 1: Analyzing the Efficiency of Algorithms Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu What is an Algorithm?

More information

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018 CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2018 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis

More information

CS F-01 Algorithm Analysis 1

CS F-01 Algorithm Analysis 1 CS673-016F-01 Algorithm Analysis 1 01-0: Syllabus Office Hours Course Text Prerequisites Test Dates & Testing Policies Try to combine tests Grading Policies 01-1: How to Succeed Come to class. Pay attention.

More information

Algorithms and Theory of Computation. Lecture 2: Big-O Notation Graph Algorithms

Algorithms and Theory of Computation. Lecture 2: Big-O Notation Graph Algorithms Algorithms and Theory of Computation Lecture 2: Big-O Notation Graph Algorithms Xiaohui Bei MAS 714 August 14, 2018 Nanyang Technological University MAS 714 August 14, 2018 1 / 20 O, Ω, and Θ Nanyang Technological

More information

Compare the growth rate of functions

Compare the growth rate of functions Compare the growth rate of functions We have two algorithms A 1 and A 2 for solving the same problem, with runtime functions T 1 (n) and T 2 (n), respectively. Which algorithm is more efficient? We compare

More information

Review Of Topics. Review: Induction

Review Of Topics. Review: Induction Review Of Topics Asymptotic notation Solving recurrences Sorting algorithms Insertion sort Merge sort Heap sort Quick sort Counting sort Radix sort Medians/order statistics Randomized algorithm Worst-case

More information

Theory of Computation

Theory of Computation Theory of Computation Dr. Sarmad Abbasi Dr. Sarmad Abbasi () Theory of Computation 1 / 33 Lecture 20: Overview Incompressible strings Minimal Length Descriptions Descriptive Complexity Dr. Sarmad Abbasi

More information

Agenda. We ve discussed

Agenda. We ve discussed Agenda We ve discussed Now Next C++ basics Some built-in data structures and their applications: stack, map, vector, array The Fibonacci example showing the importance of good algorithms and asymptotic

More information