Comparison of functions. Comparison of functions. Proof for reflexivity. Proof for transitivity. Reflexivity:

Size: px
Start display at page:

Download "Comparison of functions. Comparison of functions. Proof for reflexivity. Proof for transitivity. Reflexivity:"

Transcription

1 Comparison of functions Comparison of functions Reading: Cormen et al, Section 3. (for slide 7 and later slides) Transitivity f (n) = (g(n)) and g(n) = (h(n)) imply f (n) = (h(n)) Reflexivity: f (n) = (f (n)) f (n) =O(f (n)) f (n) = (f (n)) f (n) =O(g(n)) and g(n) =O(h(n)) imply f (n) =O(h(n)) Reflexivity does not hold for o() and!( ). E.g., ln n 6= o(ln n). f (n) = (g(n)) and g(n) = (h(n)) imply f (n) = (h(n)) Symmetry: f (n) =o(g(n)) and g(n) =o(h(n)) imply f (n) =o(h(n)) f (n) = (g(n)) if and only if g(n) = (f (n)) f (n) =!(g(n)) and g(n) =!(h(n)) imply f (n) =!(h(n)) Examples: n = O(ln n) andlnn = O(n3 )imply n = O(n3 ). 3n 3 + n = (3n 3 )and3n 3 = (n 3 )imply3n 3 + n = (n 3 ). Symmetry does not hold for O(), (), o() and!(). For example, ln ln n = O(ln n), but ln n 6= O(ln ln n). Transpose symmetry: f (n) =O(g(n)) if and only if g(n) = (f (n)). f (n) =o(g(n)) if and only if g(n) =!(f (n)). 3 COMP3600/6466 Algorithms 08 Lecture 3 COMP3600/6466 Algorithms 08 Lecture 3 3 Proof for transitivity f (n) =O(g(n)) and g(n) =O(h(n)) imply f (n) =O(h(n)) f (n) =O(g(n)) means: There are constants c > 0andn > 0 such that 0 apple f (n) apple c g(n), for all n n. g(n) =O(h(n)) means: There are constants c > 0andn > 0 such that 0 apple g(n) apple c h(n), for all n n. Thus 0 apple f (n) apple c g(n) apple c (c h(n)), for all n max{n, n }. Since c = c c and max{n, n } are positive constants, it follows that f (n) = O(h(n)), by the definition of the O-notation. f (n) = (f (n)) Proof for reflexivity f (n) = (f (n)) means: There are constants c > 0andn 0 > 0 such that 0 apple cf (n) apple f (n), for n n 0. This is true, because f (n) apple f (n), for all positive integers, and f (n) is assumed to be asymptotically nonnegative. More precisely, c = and some large enough n 0 satisfy the definition, so f (n) = (f (n)) follows. COMP3600/6466 Algorithms 08 Lecture 3 COMP3600/6466 Algorithms 08 Lecture 3 4 4

2 Proof for symmetry Standard notations and common functions f (n) = (g(n)) if and only if g(n) = (f (n)) We show f (n) = (g(n)) implies g(n) = (f (n)). The reverse direction can be proven similarly. f (n) = (g(n)) means: There are constants c > 0, c > 0, and n 0 > 0 such that 0 apple c g(n) apple f (n) apple c g(n), for all n n 0. Since c g(n) apple f (n), we have g(n) apple c f (n). Similarly, since f (n) apple c g(n), we have g(n) c f (n), Monotonicity: A function f (n) ismonotonically increasing if m < n implies f (m) apple f (n) anditisstrictly increasing if m < n implies f (m) < f (n). Similarly, f (n) ismonotonically decreasing if m < n implies f (m) f (n) andstrictly decreasing if m < n implies f (m) > f (n). Floor and ceiling: For any real x, thefloor of x, denoted by bxc, is the greatest integer less than or equal to x. Theceiling of x, denoted by dxe, is the least integer greater than or equal to x. We have x < bxc applex appledxe < x +. E.g., b4.9c =4andd4.0e = 5. We thus have 0 apple c f (n) apple g(n) apple c f (n), i.e., there are constants c 0 = c > 0, c 00 = c > 0, and n 0 > 0 such that 0 apple c 0 f (n) apple g(n) apple c 00 f (n), for all n n 0. Thus g(n) = (f (n)), by the definition of the -notation. 5 Polynomials: Given a nonnegative integer d, apolynomial in n is a function of the form p(n) = P d i=0 a in i,wherea i is a constant for each i, calledacoe cient of the polynomial. The degree of a polynomial is the highest power that occurs. E.g., p(n) =3n 7 4n 5 +.n 00 is a polynomial of degree 7. 7 COMP3600/6466 Algorithms 08 Lecture 3 5 COMP3600/6466 Algorithms 08 Lecture 3 7 Proof for transpose symmetry f (n) =o(g(n)) if and only if g(n) =!(f (n)) Proof Suppose that f (n) = o(g(n)). Hence, for any positive constant c, there exists a positive constant n 0 such that 0 apple f (n) < cg(n), for all n n 0. Now let d be any positive constant. Then there exists a positive constant n 0 such that 0 apple f (n) < (/d)g(n), for all n n 0.That is, 0 apple df(n) < g(n), for all n n 0.Henceg(n) =!(f (n)). The converse is similar. So we can, in fact, define o() using!(), and conversely. COMP3600/6466 Algorithms 08 Lecture Standard notations and common functions Exponentials: For all a > 0, (a m ) n = a mn, a m a n = a m+n, lim n! ( + x n )n = e x, e ln x =ln(e x )=x. Factorials: Recall the definition of n factorial: n! = 3 (n ) n. Stirling s approximation: n! = p n n n + e n n! =o(n n ) n! =!( n ) lg(n!) = (n lg n) COMP3600/6466 Algorithms 08 Lecture 3 8 8

3 Standard notations and common functions 3 Logarithms: For all a > 0, b > 0, and c > 0, and log bases 6=, a = b log b a log b a = log c a log c b (Base of logarithm not important asymptotically) lg n log n ln n log e n lg k n =(lgn) k lg lg n =lg(lgn) A useful result from calculus (Apostol, Calculus, Volume, second edition, page 30: Iterated logarithm The iterated logarithm is a very slow growing function. lg =. lg 4 =. lg 6 = 3. lg = 4. If a > 0andb > 0, then and ln b x lim x! x a =0 [ln b n = o(n a )] lim x! x b e ax =0 [nb = o(e an )andn b = o(c n ), for c > ] COMP3600/6466 Algorithms 08 Lecture lg ( ) = 5. lg ( ) = 6. (That is, lg = 6.) COMP3600/6466 Algorithms 08 Lecture 3 Iterated logarithm lg (0) n = n, lg () n =lgn, lg () n =lglgn, lg (3) n =lglglgn,... In general: lg (k+) n =lglg (k) n. Iterated logarithm function: lg n =min{i 0 : lg (i) n apple }. Example: Determine the value of lg 6. Now lg 6 is the smallest integer i such that lg (i) 6 apple. We have lg (0) 6 = 6 > lg () 6 =lg 6 = 6 > lg () 6 =lglg () 6 = lg 6 = lg 4 =4 > lg (3) 6 =lglg () 6 =lg4=lg = > lg (4) 6 =lglg (3) 6 =lg= It follows that lg 6 = 4. apple. COMP3600/6466 Algorithms 08 Lecture Comparison of growth rates Common functions fit in a hierarchy (growth rate increases from left to right: e.g. n lg n = O(n 3 )): n lg n... lg lg n... lg n... lg n... n... n... n lg n... n 3... n... n n... e n... 3 n... n!... n n... Most of these facts we accept (and remember!) without proof; others we will prove: I We will use (without proof) that exponential functions grow faster than powers. I We do not prove that logarithmic functions grow slower than powers. I We however often show simpler relationships, for example, that higher powers grow faster than lower powers. I We will prove results like n lg n = o(n 3 ), using the fact that logarithms grow slower than powers. COMP3600/6466 Algorithms 08 Lecture 3

4 Working with asymptotic notations To simplify a function by using asymptotic notation: Take the fastest growing additive term and ignore its constant coe cient. Examples: 3n +5n += (n ) n + 4(n +lgn) n = (n 3 ) 4n +lnn n + = (n) n n + O(n 3 )= (n n ) 6 ln n + n 00 = (n 00 ) Sample proof O(g (n)) (g (n)) = O g (n).(g (n) assumed asymptotically positive) g (n) Let f (n) =O(g (n)), which means: There are constants n > 0, c > 0 such that 0 apple f (n) apple c g (n), for n n. Let f (n) = (g (n)), which means: There are constants n > 0, c > 0 such that 0 apple c g (n) apple f (n), for n n. We obtain 0 apple f (n) f (n) apple c g (n) f (n) for n max(n, n ). apple c g (n) c g (n) = c c g(n) g (n), 5n + (n) = (n ) (careful!) 3 Since c = c c and n 0 =max(n, n ) are positive constants, the statement follows. 5 COMP3600/6466 Algorithms 08 Lecture 3 3 COMP3600/6466 Algorithms 08 Lecture 3 5 Further asymptotic properties Solution to Exercise I O(g (n)+g (n)) = O(max{g (n), g (n)}) e.g., O(n 5 + log n) =O(n 5 ) I O(g (n)) + O(g (n)) = O(max{g (n), g (n)}) e.g., O(n 3 )+O(n )=O(n 3 ) I O(g (n)) O(g (n)) = O(g (n) g (n)) e.g., O n O(log n) =O log n n (g (n)) I O(g (n)) = g (n). e.g., () g (n) O(n) = n O(g (n)) I (g (n)) = O g (n). e.g., O(n ) g (n) (n) = O(n) Exercise: Try proving some of the above. Exercise: Show that O(n )=O(n) is not valid. If O(n )=O(n) were true, then, for any choice f (n) from the set O(n ), there would be a function g(n) ino(n) suchthat f (n) =g(n). In other words, O(n ) would be a subset of O(n). (Here, it is precise to use subset, because on both sides of the equation, we have well-defined sets.) However, f (n) =n is a member of O(n ) but it is not a member of O(n). Thus, O(n ) is not a subset of O(n), that is, O(n ) 6= O(n). (Note that there are many other functions in O(n ) that are not in O(n).) COMP3600/6466 Algorithms 08 Lecture COMP3600/6466 Algorithms 08 Lecture 3 6 6

5 Solution to Exercise Exercise: Prove that n + n O(ln n) =O(n ln n). We have to prove that, for any choice f (n) from the set O(ln n), there is a function g(n) ino(n ln n) suchthat n + n f (n) =g(n), that is, n + n f (n) is an element of O(n ln n). Let f (n) be an arbitrary element of O(ln n). This means that, there is a constant c > 0 such that 0 apple f (n) apple c ln n and so 0 apple n f (n) apple cn ln n, forallsu ciently large values of n. Thus 0 apple n+n f (n) apple n+c n ln n apple n ln n+c n ln n apple (c+) n ln n, for su ciently large n. By the definition of O, thismeansthat n + n f (n) =O(n ln n), as required. 7 COMP3600/6466 Algorithms 08 Lecture 3 7 Solution to Exercise Exercise: Prove that n 6=!(n ). Suppose that n =!(n ). By the definition of!-notation, for any constant c > 0, we have 0 apple cn < n,forsu ciently large n. (*) However, for c =, this gives the false statement that 0 apple n < n for su ciently large n. That is, statement (*) is not true for all c > 0, which is a contradiction. Thus the assumption that n =!(n )isfalse. COMP3600/6466 Algorithms 08 Lecture 3 8 8

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

Asymptotic notation. O-notation 2 78 and g(n) = 1 2 n2.then. O-notation 3 Example. Let f (n) =n 3 and g(n) =2n 2.Thenf (n) 6= O(g(n)).

Asymptotic notation. O-notation 2 78 and g(n) = 1 2 n2.then. O-notation 3 Example. Let f (n) =n 3 and g(n) =2n 2.Thenf (n) 6= O(g(n)). Asymptotic notation Reading: Cormen et al, Section 3.1 In the analysis of algorithms, it is common to estimate the running time in the asymptotic sense, that is, to estimate the running time for arbitrarily

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

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

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

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

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

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

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

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

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

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

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

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

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

Reminder of Asymptotic Notation. Inf 2B: Asymptotic notation and Algorithms. Asymptotic notation for Running-time

Reminder of Asymptotic Notation. Inf 2B: Asymptotic notation and Algorithms. Asymptotic notation for Running-time 1 / 18 Reminder of Asymptotic Notation / 18 Inf B: Asymptotic notation and Algorithms Lecture B of ADS thread Let f, g : N! R be functions. We say that: I f is O(g) if there is some n 0 N and some c >

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

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

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

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

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

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

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

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

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

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

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

Md Momin Al Aziz. Analysis of Algorithms. Asymptotic Notations 3 COMP Computer Science University of Manitoba

Md Momin Al Aziz. Analysis of Algorithms. Asymptotic Notations 3 COMP Computer Science University of Manitoba Md Momin Al Aziz azizmma@cs.umanitoba.ca Computer Science University of Manitoba Analysis of Algorithms Asymptotic Notations 3 COMP 2080 Outline 1. Visualization 2. Little notations 3. Properties of Asymptotic

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

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

CSE 531 Homework 1 Solution. Jiayi Xian

CSE 531 Homework 1 Solution. Jiayi Xian CSE 53 Homework Solution Jiayi Xian Fall 08 . (a) True. Since f(n) O(f(n)), clearly we have O(f(n)) O(O(f(n))). For the opposite, suppose g(n) O(O(f(n))), that is c > 0, h(n) O(f(n)), s.t g(n) c h(n) as

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

Algorithms. Adnan YAZICI Dept. of Computer Engineering Middle East Technical Univ. Ankara - TURKEY. Algorihms, A.Yazici, Fall 2007 CEng 315

Algorithms. Adnan YAZICI Dept. of Computer Engineering Middle East Technical Univ. Ankara - TURKEY. Algorihms, A.Yazici, Fall 2007 CEng 315 Algorithms Adnan YAZICI Dept. of Computer Engineering Middle East Technical Univ. Ankara - TURKEY Algorihms, A.Yazici, Fall 2007 CEng 315 1 Design and Analysis of Algorithms Aspects of studying algorithms:

More information

This chapter covers asymptotic analysis of function growth and big-o notation.

This chapter covers asymptotic analysis of function growth and big-o notation. Chapter 14 Big-O This chapter covers asymptotic analysis of function growth and big-o notation. 14.1 Running times of programs An important aspect of designing a computer programs is figuring out how well

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

Functions. Given a function f: A B:

Functions. Given a function f: A B: Functions Given a function f: A B: We say f maps A to B or f is a mapping from A to B. A is called the domain of f. B is called the codomain of f. If f(a) = b, then b is called the image of a under f.

More information

Given a sequence a 1, a 2,...of numbers, the finite sum a 1 + a 2 + +a n,wheren is an nonnegative integer, can be written

Given a sequence a 1, a 2,...of numbers, the finite sum a 1 + a 2 + +a n,wheren is an nonnegative integer, can be written A Summations When an algorithm contains an iterative control construct such as a while or for loop, its running time can be expressed as the sum of the times spent on each execution of the body of the

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

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

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

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

5 + 9(10) + 3(100) + 0(1000) + 2(10000) =

5 + 9(10) + 3(100) + 0(1000) + 2(10000) = Chapter 5 Analyzing Algorithms So far we have been proving statements about databases, mathematics and arithmetic, or sequences of numbers. Though these types of statements are common in computer science,

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

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

csci 210: Data Structures Program Analysis

csci 210: Data Structures Program Analysis csci 210: Data Structures Program Analysis 1 Summary Summary analysis of algorithms asymptotic analysis big-o big-omega big-theta asymptotic notation commonly used functions discrete math refresher READING:

More information

MATH 324 Summer 2011 Elementary Number Theory. Notes on Mathematical Induction. Recall the following axiom for the set of integers.

MATH 324 Summer 2011 Elementary Number Theory. Notes on Mathematical Induction. Recall the following axiom for the set of integers. MATH 4 Summer 011 Elementary Number Theory Notes on Mathematical Induction Principle of Mathematical Induction Recall the following axiom for the set of integers. Well-Ordering Axiom for the Integers If

More information

CS173 Running Time and Big-O. Tandy Warnow

CS173 Running Time and Big-O. Tandy Warnow CS173 Running Time and Big-O Tandy Warnow CS 173 Running Times and Big-O analysis Tandy Warnow Today s material We will cover: Running time analysis Review of running time analysis of Bubblesort Review

More information

Please give details of your answer. A direct answer without explanation is not counted.

Please give details of your answer. A direct answer without explanation is not counted. Please give details of your answer. A direct answer without explanation is not counted. Your answers must be in English. Please carefully read problem statements. During the exam you are not allowed to

More information

Problem Set 1 Solutions

Problem Set 1 Solutions Introduction to Algorithms September 24, 2004 Massachusetts Institute of Technology 6.046J/18.410J Professors Piotr Indyk and Charles E. Leiserson Handout 7 Problem Set 1 Solutions Exercise 1-1. Do Exercise

More information

Theory of Computation

Theory of Computation Theory of Computation Dr. Sarmad Abbasi Dr. Sarmad Abbasi () Theory of Computation 1 / 38 Lecture 21: Overview Big-Oh notation. Little-o notation. Time Complexity Classes Non-deterministic TMs The Class

More information

csci 210: Data Structures Program Analysis

csci 210: Data Structures Program Analysis csci 210: Data Structures Program Analysis Summary Topics commonly used functions analysis of algorithms experimental asymptotic notation asymptotic analysis big-o big-omega big-theta READING: GT textbook

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms Instructor: Sharma Thankachan Lecture 2: Growth of Function Slides modified from Dr. Hon, with permission 1 About this lecture Introduce Asymptotic Notation Q( ), O( ),

More information

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction Math 4 Summer 01 Elementary Number Theory Notes on Mathematical Induction Principle of Mathematical Induction Recall the following axiom for the set of integers. Well-Ordering Axiom for the Integers If

More information

Design and Analysis of Algorithms. Part 1 Program Costs and Asymptotic Notations

Design and Analysis of Algorithms. Part 1 Program Costs and Asymptotic Notations Design and Analysis of Algorithms Part 1 Program Costs and Asymptotic Notations Tom Melham Hilary Term 2015 DAA 2015 1. Program costs and asymptotic notations 1 / 35 Fast computers vs efficient algorithms

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

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

Mathematical Background. e x2. log k. a+b a + b. Carlos Moreno uwaterloo.ca EIT e π i 1 = 0.

Mathematical Background. e x2. log k. a+b a + b. Carlos Moreno uwaterloo.ca EIT e π i 1 = 0. Mathematical Background Carlos Moreno cmoreno @ uwaterloo.ca EIT-4103 N k=0 log k 0 e x2 e π i 1 = 0 dx a+b a + b https://ece.uwaterloo.ca/~cmoreno/ece250 Mathematical Background Standard reminder to set

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

Intro to Theory of Computation

Intro to Theory of Computation Intro to Theory of Computation LECTURE 22 Last time Review Today: Finish recursion theorem Complexity theory Exam 2 solutions out Homework 9 out Sofya Raskhodnikova L22.1 I-clicker question (frequency:

More information

Exercise Sheet #1 Solutions, Computer Science, A M. Hallett, K. Smith a k n b k = n b + k. a k n b k c 1 n b k. a k n b.

Exercise Sheet #1 Solutions, Computer Science, A M. Hallett, K. Smith a k n b k = n b + k. a k n b k c 1 n b k. a k n b. Exercise Sheet #1 Solutions, Computer Science, 308-251A M. Hallett, K. Smith 2002 Question 1.1: Prove (n + a) b = Θ(n b ). Binomial Expansion: Show O(n b ): (n + a) b = For any c 1 > b = O(n b ). Show

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

Section 1.8 The Growth of Functions. We quantify the concept that g grows at least as fast as f.

Section 1.8 The Growth of Functions. We quantify the concept that g grows at least as fast as f. Section 1.8 The Growth of Functions We quantify the concept that g grows at least as fast as f. What really matters in comparing the complexity of algorithms? We only care about the behavior for large

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

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

Introduction to Algorithms: Asymptotic Notation

Introduction to Algorithms: Asymptotic Notation Introduction to Algorithms: Asymptotic Notation Why Should We Care? (Order of growth) CS 421 - Analysis of Algorithms 2 Asymptotic Notation O-notation (upper bounds): that 0 f(n) cg(n) for all n n. 0 CS

More information

Introduction to Algorithms and Asymptotic analysis

Introduction to Algorithms and Asymptotic analysis Indian Institute of Information Technology Design and Manufacturing, Kancheepuram Chennai 600 127, India An Autonomous Institute under MHRD, Govt of India An Institute of National Importance COM 501 Advanced

More information

An analogy from Calculus: limits

An analogy from Calculus: limits COMP 250 Fall 2018 35 - big O Nov. 30, 2018 We have seen several algorithms in the course, and we have loosely characterized their runtimes in terms of the size n of the input. We say that the algorithm

More information

Foundations II: Data Structures and Algorithms

Foundations II: Data Structures and Algorithms Foundations II: Data Structures and Algorithms Instructor : Yusu Wang Topic 1 : Introduction and Asymptotic notation Course Information Course webpage http://www.cse.ohio-state.edu/~yusu/courses/2331 Office

More information

Algorithm. Executing the Max algorithm. Algorithm and Growth of Functions Benchaporn Jantarakongkul. (algorithm) ก ก. : ก {a i }=a 1,,a n a i N,

Algorithm. Executing the Max algorithm. Algorithm and Growth of Functions Benchaporn Jantarakongkul. (algorithm) ก ก. : ก {a i }=a 1,,a n a i N, Algorithm and Growth of Functions Benchaporn Jantarakongkul 1 Algorithm (algorithm) ก ก ก ก ก : ก {a i }=a 1,,a n a i N, ก ก : 1. ก v ( v ก ก ก ก ) ก ก a 1 2. ก a i 3. a i >v, ก v ก a i 4. 2. 3. ก ก ก

More information

CSCE 222 Discrete Structures for Computing. Review for the Final. Hyunyoung Lee

CSCE 222 Discrete Structures for Computing. Review for the Final. Hyunyoung Lee CSCE 222 Discrete Structures for Computing Review for the Final! Hyunyoung Lee! 1 Final Exam Section 501 (regular class time 8:00am) Friday, May 8, starting at 1:00pm in our classroom!! Section 502 (regular

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

Section 3.2 The Growth of Functions. We quantify the concept that g grows at least as fast as f.

Section 3.2 The Growth of Functions. We quantify the concept that g grows at least as fast as f. Section 3.2 The Growth of Functions We quantify the concept that g grows at least as fast as f. What really matters in comparing the complexity of algorithms? We only care about the behavior for large

More information

(Infinite) Series Series a n = a 1 + a 2 + a a n +...

(Infinite) Series Series a n = a 1 + a 2 + a a n +... (Infinite) Series Series a n = a 1 + a 2 + a 3 +... + a n +... What does it mean to add infinitely many terms? The sequence of partial sums S 1, S 2, S 3, S 4,...,S n,...,where nx S n = a i = a 1 + a 2

More information

Mid-term Exam Answers and Final Exam Study Guide CIS 675 Summer 2010

Mid-term Exam Answers and Final Exam Study Guide CIS 675 Summer 2010 Mid-term Exam Answers and Final Exam Study Guide CIS 675 Summer 2010 Midterm Problem 1: Recall that for two functions g : N N + and h : N N +, h = Θ(g) iff for some positive integer N and positive real

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

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

Algorithm efficiency analysis

Algorithm efficiency analysis Algorithm efficiency analysis Mădălina Răschip, Cristian Gaţu Faculty of Computer Science Alexandru Ioan Cuza University of Iaşi, Romania DS 2017/2018 Content Algorithm efficiency analysis Recursive function

More information

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2 MA008 p.1/36 MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2 Dr. Markus Hagenbuchner markus@uow.edu.au. MA008 p.2/36 Content of lecture 2 Examples Review data structures Data types vs. data

More information

1 The distributive law

1 The distributive law THINGS TO KNOW BEFORE GOING INTO DISCRETE MATHEMATICS The distributive law The distributive law is this: a(b + c) = ab + bc This can be generalized to any number of terms between parenthesis; for instance:

More information

Recurrences COMP 215

Recurrences COMP 215 Recurrences COMP 215 Analysis of Iterative Algorithms //return the location of the item matching x, or 0 if //no such item is found. index SequentialSearch(keytype[] S, in, keytype x) { index location

More information

Mat Week 6. Fall Mat Week 6. Algorithms. Properties. Examples. Searching. Sorting. Time Complexity. Example. Properties.

Mat Week 6. Fall Mat Week 6. Algorithms. Properties. Examples. Searching. Sorting. Time Complexity. Example. Properties. Fall 2013 Student Responsibilities Reading: Textbook, Section 3.1 3.2 Assignments: 1. for sections 3.1 and 3.2 2. Worksheet #4 on Execution s 3. Worksheet #5 on Growth Rates Attendance: Strongly Encouraged

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

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

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

Student Responsibilities Week 6. Mat Properties of Algorithms. 3.1 Algorithms. Finding the Maximum Value in a Finite Sequence Pseudocode

Student Responsibilities Week 6. Mat Properties of Algorithms. 3.1 Algorithms. Finding the Maximum Value in a Finite Sequence Pseudocode Student Responsibilities Week 6 Mat 345 Week 6 Reading: Textbook, Section 3.1 3. Assignments: 1. for sections 3.1 and 3.. Worksheet #4 on Execution Times 3. Worksheet #5 on Growth Rates Attendance: Strongly

More information

Computational Complexity - Pseudocode and Recursions

Computational Complexity - Pseudocode and Recursions Computational Complexity - Pseudocode and Recursions Nicholas Mainardi 1 Dipartimento di Elettronica e Informazione Politecnico di Milano nicholas.mainardi@polimi.it June 6, 2018 1 Partly Based on Alessandro

More information

MATH 22 FUNCTIONS: ORDER OF GROWTH. Lecture O: 10/21/2003. The old order changeth, yielding place to new. Tennyson, Idylls of the King

MATH 22 FUNCTIONS: ORDER OF GROWTH. Lecture O: 10/21/2003. The old order changeth, yielding place to new. Tennyson, Idylls of the King MATH 22 Lecture O: 10/21/2003 FUNCTIONS: ORDER OF GROWTH The old order changeth, yielding place to new. Tennyson, Idylls of the King Men are but children of a larger growth. Dryden, All for Love, Act 4,

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

Data structures Exercise 1 solution. Question 1. Let s start by writing all the functions in big O notation:

Data structures Exercise 1 solution. Question 1. Let s start by writing all the functions in big O notation: Data structures Exercise 1 solution Question 1 Let s start by writing all the functions in big O notation: f 1 (n) = 2017 = O(1), f 2 (n) = 2 log 2 n = O(n 2 ), f 3 (n) = 2 n = O(2 n ), f 4 (n) = 1 = O

More information

MATH 117 LECTURE NOTES

MATH 117 LECTURE NOTES MATH 117 LECTURE NOTES XIN ZHOU Abstract. This is the set of lecture notes for Math 117 during Fall quarter of 2017 at UC Santa Barbara. The lectures follow closely the textbook [1]. Contents 1. The set

More information

Math 2602 Finite and Linear Math Fall 14. Homework 8: Core solutions

Math 2602 Finite and Linear Math Fall 14. Homework 8: Core solutions Math 2602 Finite and Linear Math Fall 14 Homework 8: Core solutions Review exercises for Chapter 5 page 183 problems 25, 26a-26b, 29. Section 8.1 on page 252 problems 8, 9, 10, 13. Section 8.2 on page

More information

The Growth of Functions. A Practical Introduction with as Little Theory as possible

The Growth of Functions. A Practical Introduction with as Little Theory as possible The Growth of Functions A Practical Introduction with as Little Theory as possible Complexity of Algorithms (1) Before we talk about the growth of functions and the concept of order, let s discuss why

More information

13 Lecture 13 L Hospital s Rule and Taylor s Theorem

13 Lecture 13 L Hospital s Rule and Taylor s Theorem 3 Lecture 3 L Hospital s Rule and Taylor s Theorem 3 L Hospital s Rule Theorem 3 L Hospital s Rule) Let a R or a = and functions f,g : a,b) R satisfy the following properties ) f,g are differentiable on

More information

M17 MAT25-21 HOMEWORK 6

M17 MAT25-21 HOMEWORK 6 M17 MAT25-21 HOMEWORK 6 DUE 10:00AM WEDNESDAY SEPTEMBER 13TH 1. To Hand In Double Series. The exercises in this section will guide you to complete the proof of the following theorem: Theorem 1: Absolute

More information

Ph219/CS219 Problem Set 3

Ph219/CS219 Problem Set 3 Ph19/CS19 Problem Set 3 Solutions by Hui Khoon Ng December 3, 006 (KSV: Kitaev, Shen, Vyalyi, Classical and Quantum Computation) 3.1 The O(...) notation We can do this problem easily just by knowing the

More information

Analysis of Algorithms [Reading: CLRS 2.2, 3] Laura Toma, csci2200, Bowdoin College

Analysis of Algorithms [Reading: CLRS 2.2, 3] Laura Toma, csci2200, Bowdoin College Analysis of Algorithms [Reading: CLRS 2.2, 3] Laura Toma, csci2200, Bowdoin College Why analysis? We want to predict how the algorithm will behave (e.g. running time) on arbitrary inputs, and how it will

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

Electrical & Computer Engineering University of Waterloo Canada February 26, 2007

Electrical & Computer Engineering University of Waterloo Canada February 26, 2007 : Electrical & Computer Engineering University of Waterloo Canada February 26, 2007 We want to choose the best algorithm or data structure for the job. Need characterizations of resource use, e.g., time,

More information

A SUMMARY OF RECURSION SOLVING TECHNIQUES

A SUMMARY OF RECURSION SOLVING TECHNIQUES A SUMMARY OF RECURSION SOLVING TECHNIQUES KIMMO ERIKSSON, KTH These notes are meant to be a complement to the material on recursion solving techniques in the textbook Discrete Mathematics by Biggs. In

More information

Enumerate all possible assignments and take the An algorithm is a well-defined computational

Enumerate all possible assignments and take the An algorithm is a well-defined computational EMIS 8374 [Algorithm Design and Analysis] 1 EMIS 8374 [Algorithm Design and Analysis] 2 Designing and Evaluating Algorithms A (Bad) Algorithm for the Assignment Problem Enumerate all possible assignments

More information