Lecture 11. Master Theorem for analyzing Recursive relations

Slides:



Advertisements
Similar presentations
Divide-and-Conquer 7 2  9 4   2   4   7
Advertisements

Data Structures Lecture 9 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
5/5/20151 Analysis of Algorithms Lecture 6&7: Master theorem and substitution method.
Divide-and-Conquer Recursive in structure –Divide the problem into several smaller sub-problems that are similar to the original but smaller in size –Conquer.
1 Divide-and-Conquer CSC401 – Analysis of Algorithms Lecture Notes 11 Divide-and-Conquer Objectives: Introduce the Divide-and-conquer paradigm Review the.
Master Theorem Section 7.3 of Rosen Spring 2010 CSCE 235 Introduction to Discrete Structures Course web-page: cse.unl.edu/~cse235 Questions:
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Updates HW#1 has been delayed until next MONDAY. There were two errors in the assignment Merge sort runs in Θ(n log n). Insertion sort runs in Θ(n2).
Recurrences Part 3. Recursive Algorithms Recurrences are useful for analyzing recursive algorithms Recurrence – an equation or inequality that describes.
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions Analysis of.
Recurrence Relations Connection to recursive algorithms Techniques for solving them.
Analysis of Algorithms CS 477/677 Recurrences Instructor: George Bebis (Appendix A, Chapter 4)
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions BIL741: Advanced.
Analysis of Recursive Algorithms October 29, 2014
Divide-and-Conquer 7 2  9 4   2   4   7
Analysis of Algorithms
Analysis of Algorithms CS 477/677
Analyzing Recursive Algorithms A recursive algorithm can often be described by a recurrence equation that describes the overall runtime on a problem of.
MCA 202: Discrete Mathematics Instructor Neelima Gupta
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
1 Computer Algorithms Lecture 7 Master Theorem Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
DR. NAVEED AHMAD DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF PESHAWAR LECTURE-5 Advance Algorithm Analysis.
10/25/20151 CS 3343: Analysis of Algorithms Lecture 6&7: Master theorem and substitution method.
Introduction to Algorithms 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.
Recurrences David Kauchak cs161 Summer Administrative Algorithms graded on efficiency! Be specific about the run times (e.g. log bases) Reminder:
1 Algorithms CSCI 235, Fall 2015 Lecture 6 Recurrences.
Recurrences – II. Comp 122, Spring 2004.
Lecture 5 Today, how to solve recurrences We learned “guess and proved by induction” We also learned “substitution” method Today, we learn the “master.
Divide and Conquer. Recall Divide the problem into a number of sub-problems that are smaller instances of the same problem. Conquer the sub-problems by.
1Computer Sciences. 2 GROWTH OF FUNCTIONS 3.2 STANDARD NOTATIONS AND COMMON FUNCTIONS.
Master Method Some of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Recurrences (in color) It continues…. Recurrences When an algorithm calls itself recursively, its running time is described by a recurrence. When an algorithm.
Mathematical Induction I Lecture 19 Section 4.2 Mon, Feb 14, 2005.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Recurrences It continues… Jeff Chastine. Recurrences When an algorithm calls itself recursively, its running time is described by a recurrence. A recurrence.
Recursion Ali.
Mathematical Foundations (Solving Recurrence)
Introduction to Algorithms: Recurrences
Divide-and-Conquer 6/30/2018 9:16 AM
Chapter 4: Divide and Conquer
Design and Analysis of Algorithms
Algorithm : Design & Analysis [4]
CS 3343: Analysis of Algorithms
Advance Analysis of Lecture No 9 Institute of Southern Punjab Multan
Introduction to Algorithms 6.046J
Master Theorem Section 7.3 of Rosen Fall 2008
Algorithms and Data Structures Lecture III
Divide-and-Conquer 7 2  9 4   2   4   7
Recursion-tree method
Ch 4: Recurrences Ming-Te Chi
CS 3343: Analysis of Algorithms
Master Theorem Section 8.3 of Rosen Spring 2017
Master Theorem Section 8.3 of Rosen Spring 2012
Divide-and-Conquer 7 2  9 4   2   4   7
Analysis of Algorithms
At the end of this session, learner will be able to:
Algorithms Recurrences.
CS200: Algorithm Analysis
Algorithms CSCI 235, Spring 2019 Lecture 6 Recurrences
Divide-and-Conquer 7 2  9 4   2   4   7
Algorithms CSCI 235, Spring 2019 Lecture 8 Recurrences III
Master Theorem Section 8.3 of Rosen Spring 2013
Master Theorem Section 8.3 of Rosen Spring 2018
Algorithms and Data Structures Lecture III
Divide-and-Conquer 7 2  9 4   2   4   7
Presentation transcript:

Lecture 11. Master Theorem for analyzing Recursive relations

There are four methods to solve a recursive relation Recap There are four methods to solve a recursive relation Iterative Substitution Tree method Master Theorem In iterative method you will Convert the recurrence into a summation and try to bound it using known series. In substitution method, you will use guess or induction process to solve a recursive relation In Tree method, you will form a tree and then sum up the values of nodes and also use gueses

Master Theorem Let T(n) be a monotonically increasing function that satisfies T(n) = a T(n/b) + f(n) T(1) = c where a  1, b  2, c>0. If f(n) is (nd) where d  0 then if a < bd T(n) = If a = bd if a > bd

Master Theorem: Pitfalls You cannot use the Master Theorem if T(n) is not monotone, e.g. T(n) = sin(x) f(n) is not a polynomial, e.g., T(n)=2T(n/2)+2n b cannot be expressed as a constant, e.g. Note that the Master Theorem does not solve the recurrence equation Does the base case remain a concern?

Master Theorem: Example 1 Let T(n) = T(n/2) + ½ n2 + n. What are the parameters? a = b = d = Therefore, which condition applies? 1 if a < bd T(n) = If a = bd if a > bd 2 2 1 < 22, case 1 applies We conclude that T(n)  (nd) =  (n2)

Master Theorem: Example 2 Let T(n)= 2 T(n/4) + n + 42. What are the parameters? a = b = d = Therefore, which condition applies? 2 if a < bd T(n) = If a = bd if a > bd 4 1/2 2 = 41/2, case 2 applies We conclude that

Master Theorem: Example 3 Let T(n)= 3 T(n/2) + 3/4n + 1. What are the parameters? a = b = d = Therefore, which condition applies? 3 if a < bd T(n) = If a = bd if a > bd 2 1 3 > 21, case 3 applies We conclude that Note that log231.584…, can we say that T(n)   (n1.584) No, because log231.5849… and n1.584   (n1.5849)

Master Theorem: Example 4 Let T(n)= 2T(n/2) + nlogn. What are the parameters? a = b = d = Therefore, which condition applies? 2 if a < bd T(n) = If a = bd if a > bd 2 1 2 = 21, case 2 applies We conclude that T(n) = Θ ( n1 log n) = Θ (nlogn)

Master Theorem: Example 5 Let T(n)= T(n/3) + nlogn. What are the parameters? a = b = d = Therefore, which condition applies? 1 if a < bd T(n) = If a = bd if a > bd 3 1 1 < 31, case 1 applies We conclude that T(n) = Θ ( n1 ) = Θ (n)

Master Theorem: Example 6 Let T(n)= 4T(n/2) + n. What are the parameters? a = b = d = Therefore, which condition applies? 4 if a < bd T(n) = If a = bd if a > bd 2 1 4 > 21, case 3 applies We conclude that T(n) = Θ ( logba ) = Θ (log24) Note that log241.684…, can we say that T(n)   (n1.684)

Master Theorem: Example 7 Let T(n)= 8T(n/2) + n2. What are the parameters? a = b = d = Therefore, which condition applies? 8 if a < bd T(n) = If a = bd if a > bd 2 2 8 > 22, case 3 applies We conclude that T(n) = Θ ( logb8 ) = Θ (log28) Note that log281.784…, can we say that T(n)   (n1.784)

Master Theorem: Example 8 Let T(n)= 9T(n/3) + n3. What are the parameters? a = b = d = Therefore, which condition applies? 9 if a < bd T(n) = If a = bd if a > bd 3 3 9 = 33, case 2 applies We conclude that T(n) = Θ ( n3 log n) = Θ (n3logn)

Master Theorem: Example 9 Let T(n)= T(n/2) + 1. What are the parameters? a = b = d = Therefore, which condition applies? 1 if a < bd T(n) = If a = bd if a > bd 2 1 = 20, case 2 applies We conclude that T(n) = Θ ( n0logn) = Θ (logn)

Recurrence Relation

Iterative Substitution In the iterative substitution, or “plug-and-chug,” technique, we iteratively apply the recurrence equation to itself and see if we can find a pattern: Note that base, T(n)=b, case occurs when 2i=n. That is, i = log n. So, Thus, T(n) is O(n log n).

The Recursion Tree Draw the recursion tree for the recurrence relation and look for a pattern: time bn … depth T’s size 1 n 2 n/2 i 2i n/2i … Total time = bn + bn log n

Guess-and-Test Method In the guess-and-test method, we guess a closed form solution and then try to prove it is true by induction: Guess: T(n) < cn log n. Wrong: we cannot make this last line be less than cn log n

Guess-and-Test Method, Part 2 Recall the recurrence equation: Guess #2: T(n) < cn log2 n. if c > b. So, T(n) is O(n log2 n). In general, to use this method, you need to have a good guess and you need to be good at induction proofs.

Master Theorem: 2 = 21, case 2 applies We conclude that Let T(n)= 2T(n/2) + bnlogn. What are the parameters? a = b = d = Therefore, which condition applies? 2 if a < bd T(n) = If a = bd if a > bd 2 1 2 = 21, case 2 applies We conclude that T(n) = Θ ( n1 log n) = Θ (nlogn)

Let T(n) be a monotonically increasing function that satisfies Summary Let T(n) be a monotonically increasing function that satisfies T(n) = a T(n/b) + f(n) T(1) = c where a  1, b  2, c>0. If f(n) is (nd) where d  0 then if a < bd T(n) = If a = bd if a > bd

In next lecture, we will discuss the analysis of searching algorithms In Next Lecturer In next lecture, we will discuss the analysis of searching algorithms