Analysis of Algorithms - Using Asymptotic Bounds -

Size: px
Start display at page:

Download "Analysis of Algorithms - Using Asymptotic Bounds -"

Transcription

1 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 for algorithms Examples: f(n) = O(n ) means that: n is an asymptotic upper bound for f(n) f(n) = Ω(n) means that: n is an asymptotic lower bound for f(n) f(n) is the real execution time of the analyzed algorithm Bounds valid for large sizes of input n f(n) = Θ(n log n) means that: n log n is a lower and upper bound for f(n) We can use asymptotic bounds for individual code parts to derive asymptotic bounds for the overall algorithm Θ(g(n)) = { f(n) : there exist positive constants c 1, c, and n 0 such that 0 c 1 g(n) f(n) c g(n) for all n n 0 } Example: Single Loop Algorithm to sum all elements in an array A[ ] COST TIMES BOUNDS 1. for j 1 to length[a] c 1 n+1 Θ(n). do sum sum + A[j] c n Θ(n). return sum c 1 Θ(1) Total execution time T(n): T(n) = (c 1 n + c 1 ) + (c n) + (c ) = = Θ(n) + Θ(n) + Θ(1) = Θ(n) fl Running time is Θ(n) We can derive a bound for each stmt in isolation The individual stmt bounds together give an overall bound Asymptotic bounds & inputs Θ-notation useful for algorithms whose running time does not vary with indata for the same input size For example, MERGESORT has: T(n) = Θ(n log n) O- and Ω-notation useful for algorithms where running time varies with indata for same input size For example, INSERTIONSORT has: T(n) = Ω(n) and T(n) = O(n ) There exists no function g(n) such that T(n) = Θ(g(n)) Example: best- & worst- case Only add array elements fulfilling special property COST TIMES BOUNDS 1. for j 1 to length[a]-1 c 1 n Θ(n). if A[j] A[j-1] c n-1 Θ(n). then sum sum + A[j] c 4. return sum c 4 1 Θ(1) Best case time is when c is never executed: 0 T best (n) = Θ(n) + Θ(n) Θ(1) = Θ(n) fl T(n) = Ω(n) Worst case time is when c is always executed: n-1 T worst (n) = Θ(n) + Θ(n) + Θ(n) + Θ(1) = Θ(n) fl T(n) = O(n) fl Since T(n) = Ω(n) and T(n) = O(n) then T(n) = Θ(n) Example: MERGESORT MERGESORT(A, p, r) BOUNDS 1. if p < r Θ(1). then q (p + r)/ Θ(1). MERGESORT(A, p, q) 4. MERGESORT(A, q + 1, r) 5. MERGE(A, p, q, r) Θ(n) MERGE function code consists of several statements When called MERGE runs in linear time Gives a Θ(n) cost for MERGE in calculation for MERGESORT Constant time for base case: Θ(1) Constant time for division: Θ(1)

2 Analysis of Algorithms - Recurrences - Andreas Ermedahl MRTC (Mälardalens Real-Time Research Center) andreas.ermedahl@mdh.se Autumn 004 Recurrences To be able to compare and evaluate algorithms we need a way to describe their execution times We often like to describe the execution time of an algorithm as a function T(n) of its input size n When an algorithm contains a recursive call to itself its running time T(n) can often be described by a recurrence A recurrence is an equation or inequality that describes a function in terms of: one or more base cases, and the same function called with smaller argument Example: MERGESORT The derived recurrence for the MERGESORT running time T(n): Θ(1) ( n / ) + Θ(1) + Θ( n) a = number of subproblems = n/ = size per subproblem MERGESORT(A, p, r) 1. if p < r Base case. then q (p + r)/ Divide. MERGESORT(A, p, q) Conquer 4. MERGESORT(A, q + 1, r) Conquer 5. MERGE(A, p, q, r) Combine Constant cost for dividing subproblems Base: sort only one element otherwise Time for merging resulting subproblems Solution: T(n) = Θ(n lg n) More Examples: ( n 1) + 1 Solution: T(n) = n ( n / ) + n Solution: T(n) = n lg n + n More Examples (cont): 0 if n = ( n) + 1 if n > Solution: T(n) = n lg lg n ( n / ) + T (n / ) + n Solution: T(n) = Θ(n lg n) Solving recurrences Interesting to solve (or bound) recurrences We will demonstrate some methods for this: The Substitution method - guess a solution and use mathematical induction to show that it works The Master method provides bounds for recurrences of the form: T(n) = at(n/b) + f(n) where a 1, b > 1 and f(n) is a given function The Recursion-tree method convert the recurrence into a tree whose nodes represent costs incurred at various levels of the recursion Tree method used to generate a good guess! Note! Tree method does not generate a mathematical proof! Solution must still be proven, eg. using substitution method

3 Technicalities: Floors and ceilings We usually assume that all arguments are integers We often write T(f(n)) when we mean T( f(n) ) or T( f(n) ) Floors and ceilings are usually ignored since they only have a constant effect! For example, recurrence for MERGESORT is really: Θ(1) ( n / ) + T ( n / ) + Θ(1) + Θ( n) It is not certain that n is even! Eg. if n=11 then we get subparts of sizes 5 and 6 For all real x holds that: x-1 < x x x < x+1 We use T(n/) since constant effect only! Technicalities: Boundary conditions We usually express both the recurrence and its solution using asymptotic notation We then typically omit boundary conditions for the recurrence, Assumes solution bound by constant for sufficiently small argument For example, we normally state MERGESORT recurrence as: = T ( n / ) + Θ( n) Base-case T(1) omitted! When we desire an exact, rather than an asymptotic, solution, we need to deal with boundary conditions In practice, we just use asymptotic notations most of the time, and ignore the boundary conditions The substitution method To mathematically prove a guessed solution Requires often some effort and careful analysis to guarantee correctness Works in two steps: 1. Guess the form of the solution (bound). Use mathematical induction to find constants and show that the solution (bound) works The substitution method Example: find solution to T(n) recurrence given by: ( n / ) + n Note! No asymptotics in recurrence! 1. Guess: T(n) = n lg n + n Exact solution wanted!. Induction: Base: n =1 fl n lg n + n = 0+1 = 1 = T(n) ok! Inductive step: Inductive hypothesis is that T(k) = k lg k + k for all k < n. - We ll use this inductive hypothesis for T(n/) ( n / ) + n The substitution method Inductive hypothesis: T(k) = k lg k + k for all k < n We ll use this inductive hypothesis for T(n/) T(n) = T(n/) + n Using the induction hypothesis! = ((n/) lg (n/) + (n/)) + n = n lg n/ + n + n lg a/b = lg a lg b = n(lg n - lg ) + n + n = n lg n - n + n + n lg = 1 = n lg n + n The guess was correct! The substitution method The example did not use asymptotic notations Neither in the recurrence or in the solution Generally, we use asymptotic notations: We write the recurrence as: T(n) = T(n/) + Θ(n) We express the solution as: T(n) = O(n lg n) We could use the substitution method to verify guessed asymptotic bounds

4 The substitution method Example: find asymptotic upper bound to T(n) given by: ( n / ) + n Guess: T(n) = O(n lg n) Method: Prove by induction that there exists a constant c > 0 and some constant n 0 such that T(n) lg n for all n n 0 By definition of O The substitution method (cont) Mission: Find a n 0 and corresponding c so that T(n) lg n formula holds Base: (first try) set n 0 =1 Recurrence formula gives: T(1)=1 T(n) lg n formula gives T(1) c1 lg 1 c1 * 0 = 0 fl We have to find another base (ie another value for n 0 )! Base: (second try) set n 0 = Recurrence formula gives: T()=T( / )+=T(1)+=4 T(n) lg n formula gives T() c lg = c fl ( n / ) + n Any choice of c will suffice to make the choice of n 0 = to hold Conclusion: c = and n 0 = is a base for the induction n 0 should be found! The substitution method (cont) Induction assumption: T(k) ck lg k bound holds for k = n/ I.e. T( n/ ) c n/ lg( n/ ) is assumed to hold We want to show that it holds for T(n) Using the induction assumption Proof: Substituting into the recurrence yields: ( n / ) + n T(n) = T( n/ ) + n [using induction assumption] (c n/ lg ( n/ )) + n [since n/ n and lg( n/ ) lg(n/)] lg (n/) + n [since lg(n/) = lg n lg ] = lg n lg + n [since lg = 1] = lg n + n [since n if c 1] lg n Conclusion: T(n) = O(n lg n) since it holds that T(n) lg n for c= and all n n 0 = Expanding the recurrence An obvious idea: Expand (iterate) recurrence to a summation formula dependent only on n and initial conditions Use techniques for bounding sums to bound the solution for the recurrence Example: T(n) = T(n/4)+ Θ(n ) Generates three subproblems of 1/4 the size of the original subproblem Cost to divide problem into subproblem and merge results of subproblems bounded by Θ(n ) Expanding the recurrence (cont.) We rewrite the recurrence as follows: T(n) = T(n/4) + Expansion of T(n) gives: T(n) = + T(n/4) = = + ( + T(n/4/4)) = = + + 9T(n/16) = = + + 9c(n/16) + 7T(n/64) = = We can see a pattern in the terms generated in the summation, but it is hard to directly derive a bound We make use of a recursion tree to vizualize and increase the understanding Recursion trees Tree visualizing the recursive calls in the recurrence Useful for deriving a good guess for substitution method Has one node for each time a recursive call is made (expanding multiples of calls) Each node represent the cost of a single subproblem Typical steps performed: 1. estimate number of levels in the tree /. sum horizontally for each level in the tree. finally sum vertically to derive total cost Unbalanced trees still give upper bounds, if maximum depth is used as limit for vertical summation / /4 /4 /4 /4 c c c c c... c c

5 Cost to sort n elements T(n) Size of subproblem at depth i is n/4 i Recursion tree: Expanding expand Cost to sort n/4 elements T(n/4) Three subproblems each of size n/4 T(n/4) T(n/4) expand Cost to divide n into subproblems and combine their results T(n)=T(n/4)+ Cost to divide n/4 into subproblems and combine their results expand levels Recurrence tree: Final tree Question: 1. How many levels has the tree c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) T(n)=T(n/4)+ cost expand T(n/16) T(n/16) T(n/16) T(n/16) T(n/16) T(n/16) T(n/16) T(n/16) T(n/16) T(1) T(1) T(1) T(1) T(1) T(1)T(1) T(1) T(1) T(1) T(1)T(1)... T(1) T(1)T(1) T(1) 9 Nine subproblems each of size n/16 total: 1. Estimate height of tree Size of subproblem decrease with the distance to the root The leaf nodes appear when subproblem size is 1 At each level the size of the problem is divided by 4 Size of subproblem at depth i is n/4 i Thus, subproblem size becomes 1 when n/4 i = 1 ñ n = 4 i This is equivalent to when i = log 4 n The final tree therefore has height log 4 n and log 4 n + 1 levels Recurrence tree: Final tree Question:. What is the cost of the different tree levels levels c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) log 4 n +1 T(n)=T(n/4)+ T(1) T(1) T(1) T(1) T(1) T(1)T(1) T(1) T(1) T(1) T(1)T(1)... T(1) T(1)T(1) T(1) cost total:. Cost for levels in tree We start by investigating all nodes except the leaves Each level has three times more nodes than the level above The number of nodes at level i are therefore i At each level the size of subproblem is reduced by a factor of 4 A node at level i has a cost of c(n/4 i ) The total cost for a level = sum of cost of all nodes at that level Thus, the total cost for the nodes at level i is therefore: i * c(n/4i ) = (/16) i Recurrence tree: Final tree Question:. What is the cost for the leafs levels c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) log 4 n +1 T(n)=T(n/4)+ T(1) T(1) T(1) T(1) T(1) T(1)T(1) T(1) T(1) T(1) T(1)T(1)... T(1) T(1)T(1) T(1) cost total: (/16) (/16)

6 . Cost for leaf nodes We also need to decide the cost for the leaf nodes The last level (contaning all the leafs) has depth log 4 n The total number of nodes at the last level are therefore: log 4n = n log 4 (Using fact: log 4n = 4 log 4 log4n = 4 log 4*log 4n = 4 log 4n log4 =n log 4 ) Each node contributes with cost: T(1) The total cost for all the nodes at the last level of the tree is therefore: n log4 T(1) = Θ(n log4 ) Assuming T(1) is bound by some constant Recurrence tree: Example (cont.) Question:. What is the total cost for the whole tree levels c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) c(n/16) log 4 n +1 n log4 T(n)=T(n/4)+ T(1) T(1) T(1) T(1) T(1) T(1)T(1) T(1) T(1) T(1) T(1)T(1)... T(1) T(1)T(1) T(1) cost total: (/16) (/16) Θ(n log4 ). Total cost for whole tree We sum over all costs over all levels in the tree We obtain: Cost for leaves log4 n 1 log4 T(n) = Θ( log4 n 1 i log4 Cost for nodes = + Θ( í 0 16 above the leaves = i log4 < + Θ( Geometric series: (A.6) í = 0 16 k 1 1 x = log4 = + Θ( k = 0 1 x 1 (/16) 16 log4 = 1 + Θ( Resulting guess for: = O( T(n) = T(n/4) + Proving the obtained bound We derived a O(n ) guess for T(n)=T(n/4)+ We have not proved the bound yet! From the definition Proof by substitution method: of O-notation We want to show that T(n) dn for some constant d > 0 T( n) T ( n/ 4) + d( n/ 4) = dn + 16 dn Last step holds if d (16/1)c + Induction assumption: T(k) dk holds for k < n Set k = n/4 and use induction assumption Unbalanced trees Some recurrences gives unbalanced recursion trees Eg. recurrence T(n) = T(n/)+T(n/)+ gives tree: c(n/9) c(n/) Leftmost branch peters out after log n levels c(n/9) c(n/9) c(n/) c(4n/9) Each full level has cost Each non-full level has cost Rightmost branch peters out after log / n levels T(n) = T(n/)+T(n/)+ Unbalanced tree (cont.) The tree has log n full levels After log / n levels, the problem size is down to 1 Each level contributes Lower bound guess: T(n) dn log n = Ω(n lg n) c(n/) c(n/9) c(n/) c(n/9) c(n/9) c(4n/9) Upper bound guess: Min levels T(n) dn log / n = O(n lg n) Max levels Guesses could be proven by substitution method See course book for details

7 The Master method Cookbook method to solve recurrences on form: T(n) = at(n/b) + f(n) Suitable for n > 0, a 1 and b>1 For solving the kind of recurrences which often appear for divide-and-conquer algorithms a is the number of subproblems created n/b is the size of each subproblem f(n) is a function for the cost for dividing problem into subproblems and combining their solutions Can be applied in three different cases Depends on how n log b a compares with f(n) The largest one will dominate the solution The Master method The Master Method gives tight bounds for T(n) = at(n/b) + f(n) in three cases: Case 1: f(n) = O(n log b a - ε ) for some constant ε > 0 Gives solution: T(n) = Θ(n log b a ) Case : f(n) = Θ(n log b a ) Gives solution: T(n) = Θ(n log b a lg n) Case : f(n) = Ω(n log b a+ ε ) for some constant ε > 0 and f(n) satisfies that a f(n/b) cf(n) for some c < 1 Gives solution: T(n) = Θ(f(n)) The Master method Cases depend on how f(n) compares with n log b a Roughly speaking: Case 1 holds when: f(n) < n log b a Case holds when: f(n) = n log b a Case holds when: f(n) > n log b a But only roughly speaking! The cases do not cover all possible f(n) values Case 1: f(n) must be polynomially smaller than n log b a Case : f(n) must be polynomially larger than n log b a and fulfill extra regularity condition There are gaps between case 1 and and between case and not covered by theorem Means that: f(n) must be smaller than n log b a by a factor of n k for constant k > 0 Error in your printed slides! Master method: examples Examples of recurrences solvable by the Master method: T(n) = T(n/) + 1 T(n) = T(n/) + n T(n) = T(n/) + n Example of recurrence not solvable by the Master method: T(n) = T(n/) + log n Use the other methods instead! Master Method: Example The recurrence for MERGESORT is: T(n)=T(n/)+Θ(n) We set values as: a=, b= and f(n)=θ(n) We have that n log b a = n log = n Thus, f(n)=θ(n log b a ) and case applies We directly obtain T(n) = Θ(n log b a lg n) = Θ(n lg n) Much easier!!! More Examples T(n) = 5T(n/) + Θ(n ) log 5 - ε = for some constant ε > 0 We can use Case 1 fl T(n) = Θ(n log 5 ) T(n) = 5T(n/) + Θ(n ) log 5 - ε = for some constant > 0 Check regularity condition: a f(n/b) = 5(n/) = 5n /8 for c = 5/8 < 1 We can use Case fl T(n) = Θ(n )

8 Master Method The proof for the Master Method is given in section 4.4 Uses recursion tree and induction techniques You do not need to understand the proof to apply the method Just skim through section 4.4 Summary Recurrences appear frequently in running time formulas for recursive algorithms Three methods presented for solving such recurrences: The Substitution method The Recursion-tree method The Master method Next lecture: HEAPSORT The End!

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

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example Recurrence Relations Chapter 2 Divide and Conquer Equation or an inequality that describes a function by its values on smaller inputs. Recurrence relations arise when we analyze the running time of iterative

More information

Algorithms Chapter 4 Recurrences

Algorithms Chapter 4 Recurrences Algorithms Chapter 4 Recurrences Instructor: Ching Chi Lin 林清池助理教授 chingchi.lin@gmail.com Department of Computer Science and Engineering National Taiwan Ocean University Outline The substitution method

More information

Divide and Conquer. Andreas Klappenecker

Divide and Conquer. Andreas Klappenecker Divide and Conquer Andreas Klappenecker The Divide and Conquer Paradigm The divide and conquer paradigm is important general technique for designing algorithms. In general, it follows the steps: - divide

More information

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm:

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm: The maximum-subarray problem Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm: Brute force algorithm: At best, θ(n 2 ) time complexity 129 Can we do divide

More information

1 Substitution method

1 Substitution method Recurrence Relations we have discussed asymptotic analysis of algorithms and various properties associated with asymptotic notation. As many algorithms are recursive in nature, it is natural to analyze

More information

Chapter 4. Recurrences

Chapter 4. Recurrences Chapter 4. Recurrences Outline Offers three methods for solving recurrences, that is for obtaining asymptotic bounds on the solution In the substitution method, we guess a bound and then use mathematical

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

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

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms. Solving recurrences Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms Example: Merge-Sort(A, p, r) 1: if p < r then 2: q (p + r)/2 3: Merge-Sort(A,

More information

Data Structures and Algorithms Chapter 3

Data Structures and Algorithms Chapter 3 Data Structures and Algorithms Chapter 3 1. Divide and conquer 2. Merge sort, repeated substitutions 3. Tiling 4. Recurrences Recurrences Running times of algorithms with recursive calls can be described

More information

Asymptotic Analysis and Recurrences

Asymptotic Analysis and Recurrences Appendix A Asymptotic Analysis and Recurrences A.1 Overview We discuss the notion of asymptotic analysis and introduce O, Ω, Θ, and o notation. We then turn to the topic of recurrences, discussing several

More information

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem CS 577 Introduction to Algorithms: Jin-Yi Cai University of Wisconsin Madison In the last class, we described InsertionSort and showed that its worst-case running time is Θ(n 2 ). Check Figure 2.2 for

More information

CS 5321: Advanced Algorithms Analysis Using Recurrence. Acknowledgement. Outline

CS 5321: Advanced Algorithms Analysis Using Recurrence. Acknowledgement. Outline CS 5321: Advanced Algorithms Analysis Using Recurrence Ali Ebnenasir Department of Computer Science Michigan Technological University Acknowledgement Eric Torng Moon Jung Chung Charles Ofria Outline Motivating

More information

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch]

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch] Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch] Divide and Conquer Paradigm An important general technique for designing algorithms: divide problem into subproblems recursively

More information

CS 5321: Advanced Algorithms - Recurrence. Acknowledgement. Outline. Ali Ebnenasir Department of Computer Science Michigan Technological University

CS 5321: Advanced Algorithms - Recurrence. Acknowledgement. Outline. Ali Ebnenasir Department of Computer Science Michigan Technological University CS 5321: Advanced Algorithms - Recurrence Ali Ebnenasir Department of Computer Science Michigan Technological University Acknowledgement Eric Torng Moon Jung Chung Charles Ofria Outline Motivating example:

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

Mergesort and Recurrences (CLRS 2.3, 4.4)

Mergesort and Recurrences (CLRS 2.3, 4.4) Mergesort and Recurrences (CLRS 2.3, 4.4) We saw a couple of O(n 2 ) algorithms for sorting. Today we ll see a different approach that runs in O(n lg n) and uses one of the most powerful techniques for

More information

Inf 2B: Sorting, MergeSort and Divide-and-Conquer

Inf 2B: Sorting, MergeSort and Divide-and-Conquer Inf 2B: Sorting, MergeSort and Divide-and-Conquer Lecture 7 of ADS thread Kyriakos Kalorkoti School of Informatics University of Edinburgh The Sorting Problem Input: Task: Array A of items with comparable

More information

What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency Asympt

What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency Asympt Lecture 3 The Analysis of Recursive Algorithm Efficiency What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency

More information

Design and Analysis of Algorithms Recurrence. Prof. Chuhua Xian School of Computer Science and Engineering

Design and Analysis of Algorithms Recurrence. Prof. Chuhua Xian   School of Computer Science and Engineering Design and Analysis of Algorithms Recurrence Prof. Chuhua Xian Email: chhxian@scut.edu.cn School of Computer Science and Engineering Course Information Instructor: Chuhua Xian ( 冼楚华 ) Email: chhxian@scut.edu.cn

More information

Data Structures and Algorithms CMPSC 465

Data Structures and Algorithms CMPSC 465 Data Structures and Algorithms CMPSC 465 LECTURE 9 Solving recurrences Substitution method Adam Smith S. Raskhodnikova and A. Smith; based on slides by E. Demaine and C. Leiserson Review question Draw

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

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

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/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication

CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication Integer multiplication Say we have 5 baskets with 8 apples in each How do we determine how many apples we have? Count them all? That would take

More information

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d CS161, Lecture 4 Median, Selection, and the Substitution Method Scribe: Albert Chen and Juliana Cook (2015), Sam Kim (2016), Gregory Valiant (2017) Date: January 23, 2017 1 Introduction Last lecture, we

More information

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101 A design paradigm Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/17 112 Multiplying complex numbers (from Jeff Edmonds slides) INPUT: Two pairs of integers, (a,b),

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

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2 In-Class Soln 1 Let f(n) be an always positive function and let g(n) = f(n) log n. Show that f(n) = o(g(n)) CS 361, Lecture 4 Jared Saia University of New Mexico For any positive constant c, we want to

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

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

Methods for solving recurrences

Methods for solving recurrences Methods for solving recurrences Analyzing the complexity of mergesort The merge function Consider the following implementation: 1 int merge ( int v1, int n1, int v, int n ) { 3 int r = malloc ( ( n1+n

More information

Divide and Conquer. Arash Rafiey. 27 October, 2016

Divide and Conquer. Arash Rafiey. 27 October, 2016 27 October, 2016 Divide the problem into a number of subproblems Divide the problem into a number of subproblems Conquer the subproblems by solving them recursively or if they are small, there must be

More information

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk CMPS 2200 Fall 2017 Divide-and-Conquer Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk 1 The divide-and-conquer design paradigm 1. Divide the problem (instance)

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

Introduction to Divide and Conquer

Introduction to Divide and Conquer Introduction to Divide and Conquer Sorting with O(n log n) comparisons and integer multiplication faster than O(n 2 ) Periklis A. Papakonstantinou York University Consider a problem that admits a straightforward

More information

Chapter 4 Divide-and-Conquer

Chapter 4 Divide-and-Conquer Chapter 4 Divide-and-Conquer 1 About this lecture (1) Recall the divide-and-conquer paradigm, which we used for merge sort: Divide the problem into a number of subproblems that are smaller instances of

More information

Data Structures and Algorithms Chapter 3

Data Structures and Algorithms Chapter 3 1 Data Structures and Algorithms Chapter 3 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

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

CS 2110: INDUCTION DISCUSSION TOPICS

CS 2110: INDUCTION DISCUSSION TOPICS CS 110: INDUCTION DISCUSSION TOPICS The following ideas are suggestions for how to handle your discussion classes. You can do as much or as little of this as you want. You can either present at the board,

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

Computational Complexity. This lecture. Notes. Lecture 02 - Basic Complexity Analysis. Tom Kelsey & Susmit Sarkar. Notes

Computational Complexity. This lecture. Notes. Lecture 02 - Basic Complexity Analysis. Tom Kelsey & Susmit Sarkar. Notes Computational Complexity Lecture 02 - Basic Complexity Analysis Tom Kelsey & Susmit Sarkar School of Computer Science University of St Andrews http://www.cs.st-andrews.ac.uk/~tom/ twk@st-andrews.ac.uk

More information

Appendix: Solving Recurrences

Appendix: Solving Recurrences ... O Zarathustra, who you are and must become behold you are the teacher of the eternal recurrence that is your destiny! That you as the first must teach this doctrine how could this great destiny not

More information

Week 5: Quicksort, Lower bound, Greedy

Week 5: Quicksort, Lower bound, Greedy Week 5: Quicksort, Lower bound, Greedy Agenda: Quicksort: Average case Lower bound for sorting Greedy method 1 Week 5: Quicksort Recall Quicksort: The ideas: Pick one key Compare to others: partition into

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

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

Outline. 1 Introduction. Merging and MergeSort. 3 Analysis. 4 Reference

Outline. 1 Introduction. Merging and MergeSort. 3 Analysis. 4 Reference Outline Computer Science 331 Sort Mike Jacobson Department of Computer Science University of Calgary Lecture #25 1 Introduction 2 Merging and 3 4 Reference Mike Jacobson (University of Calgary) Computer

More information

Problem 5. Use mathematical induction to show that when n is an exact power of two, the solution of the recurrence

Problem 5. Use mathematical induction to show that when n is an exact power of two, the solution of the recurrence A. V. Gerbessiotis CS 610-102 Spring 2014 PS 1 Jan 27, 2014 No points For the remainder of the course Give an algorithm means: describe an algorithm, show that it works as claimed, analyze its worst-case

More information

Objective. - mathematical induction, recursive definitions - arithmetic manipulations, series, products

Objective. - mathematical induction, recursive definitions - arithmetic manipulations, series, products Recurrences Objective running time as recursive function solve recurrence for order of growth method: substitution method: iteration/recursion tree method: MASTER method prerequisite: - mathematical induction,

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

Lecture 4. Quicksort

Lecture 4. Quicksort Lecture 4. Quicksort T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo choo@skku.edu Copyright 2000-2018 Networking

More information

Algorithm Analysis Recurrence Relation. Chung-Ang University, Jaesung Lee

Algorithm Analysis Recurrence Relation. Chung-Ang University, Jaesung Lee Algorithm Analysis Recurrence Relation Chung-Ang University, Jaesung Lee Recursion 2 Recursion 3 Recursion in Real-world Fibonacci sequence = + Initial conditions: = 0 and = 1. = + = + = + 0, 1, 1, 2,

More information

Divide and Conquer. Recurrence Relations

Divide and Conquer. Recurrence Relations Divide and Conquer Recurrence Relations Divide-and-Conquer Strategy: Break up problem into parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. 2 MergeSort Mergesort.

More information

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30,

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, Divide and Conquer CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Merging sorted lists: WHAT Given two sorted lists a 1 a 2 a 3 a k b 1 b 2 b 3 b

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

Notes for Recitation 14

Notes for Recitation 14 6.04/18.06J Mathematics for Computer Science October 4, 006 Tom Leighton and Marten van Dijk Notes for Recitation 14 1 The Akra-Bazzi Theorem Theorem 1 (Akra-Bazzi, strong form). Suppose that: is defined

More information

ECE250: Algorithms and Data Structures Analyzing and Designing Algorithms

ECE250: Algorithms and Data Structures Analyzing and Designing Algorithms ECE50: Algorithms and Data Structures Analyzing and Designing Algorithms Ladan Tahvildari, PEng, SMIEEE Associate Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng.

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

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 9 Divide and Conquer Merge sort Counting Inversions Binary Search Exponentiation Solving Recurrences Recursion Tree Method Master Theorem Sofya Raskhodnikova S. Raskhodnikova;

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

Appendix II: Solving Recurrences [Fa 10] Wil Wheaton: Embrace the dark side! Sheldon: That s not even from your franchise!

Appendix II: Solving Recurrences [Fa 10] Wil Wheaton: Embrace the dark side! Sheldon: That s not even from your franchise! Change is certain. Peace is followed by disturbances; departure of evil men by their return. Such recurrences should not constitute occasions for sadness but realities for awareness, so that one may be

More information

CS483 Design and Analysis of Algorithms

CS483 Design and Analysis of Algorithms CS483 Design and Analysis of Algorithms Chapter 2 Divide and Conquer Algorithms Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: Room 5326, Engineering Building, Thursday 4:30pm -

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17 2.1 Notes Homework 1 will be released today, and is due a week from today by the beginning

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

Design Patterns for Data Structures. Chapter 3. Recursive Algorithms

Design Patterns for Data Structures. Chapter 3. Recursive Algorithms Chapter 3 Recursive Algorithms Writing recurrences + Writing recurrences To determine the statement execution count is a two-step problem. Write down the recurrence from the recursive code for the algorithm.

More information

CS 4104 Data and Algorithm Analysis. Recurrence Relations. Modeling Recursive Function Cost. Solving Recurrences. Clifford A. Shaffer.

CS 4104 Data and Algorithm Analysis. Recurrence Relations. Modeling Recursive Function Cost. Solving Recurrences. Clifford A. Shaffer. Department of Computer Science Virginia Tech Blacksburg, Virginia Copyright c 2010,2017 by Clifford A. Shaffer Data and Algorithm Analysis Title page Data and Algorithm Analysis Clifford A. Shaffer Spring

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

CPS 616 DIVIDE-AND-CONQUER 6-1

CPS 616 DIVIDE-AND-CONQUER 6-1 CPS 616 DIVIDE-AND-CONQUER 6-1 DIVIDE-AND-CONQUER Approach 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3. Obtain solution to original (larger)

More information

Divide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14

Divide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14 Divide and Conquer Algorithms CSE 101: Design and Analysis of Algorithms Lecture 14 CSE 101: Design and analysis of algorithms Divide and conquer algorithms Reading: Sections 2.3 and 2.4 Homework 6 will

More information

Pre-lecture R: Solving Recurrences

Pre-lecture R: Solving Recurrences R Solving Recurrences R.1 Fun with Fibonacci numbers Consider the reproductive cycle of bees. Each male bee has a mother but no father; each female bee has both a mother and a father. If we examine the

More information

Chapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 5 Divide and Conquer CLRS 4.3 Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve

More information

V. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005

V. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005 V. Adamchi Recurrences Victor Adamchi Fall of 00 Plan Multiple roots. More on multiple roots. Inhomogeneous equations 3. Divide-and-conquer recurrences In the previous lecture we have showed that if the

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

Data selection. Lower complexity bound for sorting

Data selection. Lower complexity bound for sorting Data selection. Lower complexity bound for sorting Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 12 1 Data selection: Quickselect 2 Lower complexity bound for sorting 3 The

More information

Analysis of Multithreaded Algorithms

Analysis of Multithreaded Algorithms Analysis of Multithreaded Algorithms Marc Moreno Maza University of Western Ontario, London, Ontario (Canada) CS 4435 - CS 9624 (Moreno Maza) Analysis of Multithreaded Algorithms CS 4435 - CS 9624 1 /

More information

Divide-and-conquer: Order Statistics. Curs: Fall 2017

Divide-and-conquer: Order Statistics. Curs: Fall 2017 Divide-and-conquer: Order Statistics Curs: Fall 2017 The divide-and-conquer strategy. 1. Break the problem into smaller subproblems, 2. recursively solve each problem, 3. appropriately combine their answers.

More information

2.2 Asymptotic Order of Growth. definitions and notation (2.2) examples (2.4) properties (2.2)

2.2 Asymptotic Order of Growth. definitions and notation (2.2) examples (2.4) properties (2.2) 2.2 Asymptotic Order of Growth definitions and notation (2.2) examples (2.4) properties (2.2) Asymptotic Order of Growth Upper bounds. T(n) is O(f(n)) if there exist constants c > 0 and n 0 0 such that

More information

MIDTERM I CMPS Winter 2013 Warmuth

MIDTERM I CMPS Winter 2013 Warmuth test I 1 MIDTERM I CMPS 101 - Winter 2013 Warmuth With Solutions NAME: Student ID: This exam is closed book, notes, computer and cell phone. Show partial solutions to get partial credit. Make sure you

More information

CS483 Design and Analysis of Algorithms

CS483 Design and Analysis of Algorithms CS483 Design and Analysis of Algorithms Lecture 6-8 Divide and Conquer Algorithms Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: STII, Room 443, Friday 4:00pm - 6:00pm or by appointments

More information

Divide and Conquer Strategy

Divide and Conquer Strategy Divide and Conquer Strategy Algorithm design is more an art, less so a science. There are a few useful strategies, but no guarantee to succeed. We will discuss: Divide and Conquer, Greedy, Dynamic Programming.

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

Recurrence Relations

Recurrence Relations Recurrence Relations Analysis Tools S.V. N. (vishy) Vishwanathan University of California, Santa Cruz vishy@ucsc.edu January 15, 2016 S.V. N. Vishwanathan (UCSC) CMPS101 1 / 29 Recurrences Outline 1 Recurrences

More information

Midterm Exam. CS 3110: Design and Analysis of Algorithms. June 20, Group 1 Group 2 Group 3

Midterm Exam. CS 3110: Design and Analysis of Algorithms. June 20, Group 1 Group 2 Group 3 Banner ID: Name: Midterm Exam CS 3110: Design and Analysis of Algorithms June 20, 2006 Group 1 Group 2 Group 3 Question 1.1 Question 2.1 Question 3.1 Question 1.2 Question 2.2 Question 3.2 Question 3.3

More information

Divide & Conquer. CS 320, Fall Dr. Geri Georg, Instructor CS320 Div&Conq 1

Divide & Conquer. CS 320, Fall Dr. Geri Georg, Instructor CS320 Div&Conq 1 Divide & Conquer CS 320, Fall 2017 Dr. Geri Georg, Instructor georg@colostate.edu CS320 Div&Conq 1 Strategy 1. Divide the problem up into equal sized sub problems 2. Solve the sub problems recursively

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

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

Algorithms And Programming I. Lecture 5 Quicksort

Algorithms And Programming I. Lecture 5 Quicksort Algorithms And Programming I Lecture 5 Quicksort Quick Sort Partition set into two using randomly chosen pivot 88 31 25 52 14 98 62 30 23 79 14 31 2530 23 52 88 62 98 79 Quick Sort 14 31 2530 23 52 88

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

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

CS 4349 Lecture August 30th, 2017

CS 4349 Lecture August 30th, 2017 CS 4349 Lecture August 30th, 2017 Main topics for #lecture include #recurrances. Prelude I will hold an extra office hour Friday, September 1st from 3:00pm to 4:00pm. Please fill out prerequisite forms

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

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD Greedy s Greedy s Shortest path Claim 2: Let S be a subset of vertices containing s such that we know the shortest path length l(s, u) from s to any vertex in u S. Let e = (u, v) be an edge such that 1

More information

CS 161 Summer 2009 Homework #2 Sample Solutions

CS 161 Summer 2009 Homework #2 Sample Solutions CS 161 Summer 2009 Homework #2 Sample Solutions Regrade Policy: If you believe an error has been made in the grading of your homework, you may resubmit it for a regrade. If the error consists of more than

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

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

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

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 5: Divide and Conquer (Part 2) Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ A Lower Bound on Convex Hull Lecture 4 Task: sort the

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