Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 4: Recurrences.

Slides:



Advertisements
Similar presentations
한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
Advertisements

한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
Recurrences : 1 Chapter 3. Growth of function Chapter 4. Recurrences.
Divide and Conquer (Merge Sort)
5/5/20151 Analysis of Algorithms Lecture 6&7: Master theorem and substitution method.
Comp 122, Spring 2004 Divide and Conquer (Merge Sort)
September 12, Algorithms and Data Structures Lecture III Simonas Šaltenis Nykredit Center for Database Research Aalborg University
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.
11 Computer Algorithms Lecture 6 Recurrence Ch. 4 (till Master Theorem) Some of these slides are courtesy of D. Plaisted et al, UNC and M. Nicolescu, UNR.
Algorithms Recurrences. Definition – a recurrence is an equation or inequality that describes a function in terms of its value on smaller inputs Example.
Recurrence Relations Reading Material –Chapter 2 as a whole, but in particular Section 2.8 –Chapter 4 from Cormen’s Book.
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.
CS 253: Algorithms Chapter 4 Divide-and-Conquer Recurrences Master Theorem Credit: Dr. George Bebis.
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).
4.Recurrences Hsu, Lih-Hsing. Computer Theory Lab. Chapter 4P.2 Recurrences -- Substitution method Recursion-tree method Master method.
Recurrence Relations Reading Material –Chapter 2 as a whole, but in particular Section 2.8 –Chapter 4 from Cormen’s Book.
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.
Chapter 4: Solution of recurrence relationships
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.
October 1, Algorithms and Data Structures Lecture III Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Introduction to Algorithms Jiafen Liu Sept
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
1 Recurrences Algorithms Jay Urbain, PhD Credits: Discrete Mathematics and Its Applications, by Kenneth Rosen The Design and Analysis of.
1 Computer Algorithms Lecture 7 Master Theorem Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
Project 2 due … Project 2 due … Project 2 Project 2.
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
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.
4.Divide-and-Conquer Hsu, Lih-Hsing. Computer Theory Lab. Chapter 4P.2 Instruction Divide Conquer Combine.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 3.
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:
Divide-and-Conquer UNC Chapel HillZ. Guo. Divide-and-Conquer It’s a technique instead of an algorithm Recursive in structure – Divide the problem into.
Recurrences – II. Comp 122, Spring 2004.
Foundations II: Data Structures and Algorithms
Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner
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.
1Computer Sciences Department. Objectives Recurrences.  Substitution Method,  Recursion-tree method,  Master method.
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.
Divide and Conquer Faculty Name: Ruhi Fatima Topics Covered Divide and Conquer Matrix multiplication Recurrence.
BY Lecturer: Aisha Dawood. A recurrence is a function is defined in terms of:  one or more base cases, and  itself, with smaller arguments. 2.
Chapter 4: Solution of recurrence relationships Techniques: Substitution: proof by induction Tree analysis: graphical representation Master theorem: Recipe.
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
Proofs, Recursion and Analysis of Algorithms
Lecture 11. Master Theorem for analyzing Recursive relations
Chapter 4: Divide and Conquer
Advance Analysis of Lecture No 9 Institute of Southern Punjab Multan
Introduction to Algorithms 6.046J
Ch 4: Recurrences Ming-Te Chi
CS 3343: Analysis of Algorithms
Introduction to Algorithms
Divide and Conquer (Merge Sort)
Ack: Several slides from Prof. Jim Anderson’s COMP 202 notes.
Analysis of Algorithms
Algorithms Recurrences.
Quicksort Quick sort Correctness of partition - loop invariant
Presentation transcript:

Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 4: Recurrences

Overview  Define what a recurrence is  Discuss three methods of solving recurrences Substitution method Recursion-tree method Master method  Examples of each method

Definition  A recurrence is an equation or inequality that describes a function in terms of its value on smaller inputs.  Example from M ERGE -S ORT T(n) =  (1) if n=1 2T(n/2) +  (n) if n>1

Technicalities  Normally, independent variables only assume integral values  Example from M ERGE -S ORT revisited T(n) =  (1) if n=1 T(  n/2  ) + T(  n/2  ) +  (n) if n>1  For simplicity, ignore floors and ceilings – often insignificant

Technicalities  Value of T(n) assumed to be small constant for small n  Boundary conditions (small n) are also glossed over T(n) = 2T(n/2) +  (n)

Substitution Method  Involves two steps: 1.Guess the form of the solution. 2.Use mathematical induction to find the constants and show the solution works.  Drawback: applied only in cases where it is easy to guess at solution  Useful in estimating bounds on true solution even if latter is unidentified

Substitution Method  Example: T(n) = 2T(  n/2  ) + n  Guess: T(n) = O(n lg n)  Prove by induction: T(n)  cn lg n for suitable c>0.

Inductive Proof  We’ll not worry about the basis case for the moment – we’ll choose this as needed – clearly we have: T(1) =  (1)  cn lg n  Inductive hypothesis: For values of n < k the inequality holds, i.e., T(n)  cn lg n We need to show that this holds for n = k as well.

Inductive Proof  In particular, for n =  k/2 , the inductive hypothesis should hold, i.e., T(  k/2  )  c  k/2  lg  k/2  The recurrence gives us: T(k) = 2T(  k/2  ) + k Substituting the inequality above yields: T(k)  2[c  k/2  lg  k/2  ] + k

Inductive Proof Because of the non-decreasing nature of the functions involved, we can drop the “floors” and obtain: T(k)  2[c (k/2) lg (k/2)] + k Which simplifies to: T(k)  ck (lg k  lg 2) + k Or, since lg 2 = 1, we have: T(k)  ck lg k  ck + k = ck lg k + (1  c)k So if c  1, T(k)  ck lg k Q.E.D.

Recursion-Tree Method  Straightforward technique of coming up with a good guess  Can help the Substitution Method  Recursion tree: visual representation of recursive call hierarchy where each node represents the cost of a single subproblem

Recursion-Tree Method T(n) = 3T(  n/4  ) +  (n 2 )

Recursion-Tree Method T(n) = 3T(  n/4  ) +  (n 2 )

Recursion-Tree Method T(n) = 3T(  n/4  ) +  (n 2 )

Recursion-Tree Method T(n) = 3T(  n/4  ) +  (n 2 )

Recursion-Tree Method  Gathering all the costs together: T(n) = ( 3/16 ) i cn 2 +  (n log 4 3 )  i=0 log 4 n  1 T(n)  ( 3/16 ) i cn 2 + o(n)  i=0  T(n)  ( 1/(1  3/16) ) cn 2 + o(n) T(n)  ( 16/13 ) cn 2 + o(n) T(n) = O(n2)O(n2)

Recursion-Tree Method T(n) = T(n/3) + T(2n/3) + O(n)

Recursion-Tree Method  An overestimate of the total cost: T(n) = cn +  (n log 3/2 2 )  i=0 log 3/2 n  1 T(n) = O(n lg n) +  (n lg n)  Counter-indications: T(n) = O(n lg n)  Notwithstanding this, use as “guess”:

Substitution Method  Recurrence: T(n) = T(n/3) + T(2n/3) + cn  Guess: T(n) = O(n lg n)  Prove by induction: T(n)  dn lg n for suitable d > 0 (we already use c )

Inductive Proof  Again, we’ll not worry about the basis case  Inductive hypothesis: For values of n < k the inequality holds, i.e., T(n)  dn lg n We need to show that this holds for n = k as well.  In particular, for n = k/3, and n = 2k/3, the inductive hypothesis should hold…

Inductive Proof  That is T(k/3)  d k/3 lg k/3 T(2k/3)  d 2k/3 lg 2k/3 The recurrence gives us: T(k) = T(k/3) + T(2k/3) + ck Substituting the inequalities above yields: T(k)  [d (k/3) lg (k/3)] + [d (2k/3) lg (2k/3)] + ck

Inductive Proof  Expanding, we get T(k)  [d (k/3) lg k  d (k/3) lg 3] + [d (2k/3) lg k  d (2k/3) lg(3/2)] + ck Rearranging, we get: T(k)  dk lg k  d[(k/3) lg 3 + (2k/3) lg(3/2)] + ck T(k)  dk lg k  dk[lg 3  2/3] + ck When d  c/(lg3  (2/3)), we should have the desired: T(k)  dk lg k

Master Method  Provides a “cookbook” method for solving recurrences  Recurrence must be of the form: T(n) = aT(n/b) + f(n) where a  1 and b>1 are constants and f(n) is an asymptotically positive function.

Master Method  Theorem 4.1: Given the recurrence previously defined, we have: 1. If f(n) = O(n log b a   ) for some constant  >0, then T(n) =  (n log b a ) 2. If f(n) =  (n log b a ), then T(n) =  (n log b a lg n)

Master Method 3. If f(n) =  (n log b a+  ) for some constant  > 0, and if af(n/b)  cf(n) for some constant c < 1 and all sufficiently large n, then T(n) =  (f(n))

Example  Estimate bounds on the following recurrence:  Use the recursion tree method to arrive at a “guess” then verify using induction  Point out which case in the Master Method this falls in

Recursion Tree  Recurrence produces the following tree:

Cost Summation  Collecting the level-by-level costs:  A geometric series with base less than one; converges to a finite sum, hence, T(n) =  (n 2 )

Exact Calculation  If an exact solution is preferred:  Using the formula for a partial geometric series:

Exact Calculation  Solving further:

Master Theorem (Simplified)