Chapter 4. Recurrences. Outline Offers three methods for solving recurrences, that is for obtaining asymptotic bounds on the solution In the substitution.

Slides:



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

한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Divide-and-Conquer CIS 606 Spring 2010.
Ack: Several slides from Prof. Jim Anderson’s COMP 202 notes.
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)
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.
Lecture 5COMPSCI.220.FS.T Worst-Case Performance Upper bounds : simple to obtain Lower bounds : a difficult matter... Worst case data may be unlikely.
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.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
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.
Recurrences Part 3. Recursive Algorithms Recurrences are useful for analyzing recursive algorithms Recurrence – an equation or inequality that describes.
Analysis of Algorithms
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
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 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.
CSC 413/513: Intro to Algorithms Merge Sort Solving Recurrences.
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.
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
Solving Recurrences with the Substitution Method.
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.
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 4: Recurrences.
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)
Lecture 11. Master Theorem for analyzing Recursive relations
Chapter 4: Divide and Conquer
CS 3343: Analysis of Algorithms
Advance Analysis of Lecture No 9 Institute of Southern Punjab Multan
Ch 4: Recurrences Ming-Te Chi
CS 3343: Analysis of Algorithms
Divide and Conquer (Merge Sort)
Ack: Several slides from Prof. Jim Anderson’s COMP 202 notes.
Analysis of Algorithms
Introduction To Algorithms
Algorithms Recurrences.
Quicksort Quick sort Correctness of partition - loop invariant
Presentation transcript:

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 induction to prove our guess correct The recursion-tree method converts the recurrence into a tree whose nodes represent the costs incurred at various levels The master method provides bounds for the recurrence of the form

Technicalities Assumption of integer arguments to functions Boundary conditions we usually ignore –The recurrences that arises from the running time of algorithms generally have T(n)=  (1) for sufficiently small n –Changing the value of T(1), the solution typically does not change by more than a constant factor, so the order of growth is unchanged. Often omit floors, ceilings and boundary conditions Often omit floors, ceilings and boundary conditions – We forge ahead without these details and later determine whether or not they matter and it is important to know when they do matter.

When an algorithm contains a recursive call to itself, its running time can often be described by a recurrence A recurrence is a function (equation or in-equality) defined in terms of –one or more base cases, --boundary condition –itself, with smaller arguments. Example: –T (n) = 1 if n = 1, T (n-1) +1 if n > 1. Solution: T (n) = n. –T (n) = 1 if n = 1, 2T (n/2) + n if n ≥ 1. Solution: T (n) = n lg n + n Recurrence

Summary In algorithm analysis, we usually express both the recurrence and its solution using asymptotic notation Example: T(n)=2T(n/2)+  (n), with solution T(n)=  (nlgn) The boundary conditions are usually expressed as “ The boundary conditions are usually expressed as “ T(n)=1 for sufficiently small n” When we desire an exact rather than asymptotic solution, we need to deal with boundary condition In practice, we just use asymptotic notations most of the time and we ignore boundary conditions

Substitution Method The substitution method entails two steps – Guess the form of the solution – Use mathematical induction to find the constants and show that the solution works The method is powerful but only applied to cases when it is easy to guess the form of he answer The method can be used to establish either upper or lower bound on a recurrence.

The Substitution method T(n) = 2T(n/2) + n Guess:T(n) = O(n lg n) Proof: Prove that T(n)  c n lg n for c>0 Assume T(n/2)  c(n/2)lg(n/2) for some positive constant c then T(n)  2(c  n/2  lg n/2) + n = cn lg n – cn + n  cn lg nif c  1  cn lg nif c  1 Therefore, T(n) = O(n lg n)

Subtleties There are times when can correctly guess an asymptotic bound on the solution of a recurrence, but somehow the math doesn’t seem to work out in the induction There are times when can correctly guess an asymptotic bound on the solution of a recurrence, but somehow the math doesn’t seem to work out in the induction Revising the guess by subtracting a lower-order term often permits the math to go through

Several Points Making good guess Avoiding pitfalls Changing variables

The Recursion-Tree method Each code represents the cost of a single sub-problem somewhere in the set of recursive function invocations. Sum the costs within each level of the tree to obtain a set of per-level costs. Then sum all the per-level costs to determine the total cost of all levels of the recursion. It’s useful to solve the recurrence which describes the running time of a divide-and-conquer algorithm. It’s used to generate a good guess which is then verified by the substitution method. A careful drawing of a recursion tree and summing the costs can be used as a direct proof of a solution to a recurrence.

Examples T(n)=3T(n/4)=cn 2 –Substitution Method –Recursion Tree T(n)=T(n/3)+T(2n/3)+O(n) T(n)=T(n/3)+T(2n/3)+O(n)

#nodes at i th level: 3 i Size of sub- problem at i th : n/4 i =>total level: log 4 n

Validation

Another Example

Use Substitution Method to verify

Example 1. T (n) = 5T (n/2) +  (n²) vs. n² vs. n² sol.) Since log2 5 -  = 2 for some constant  > 0, use Case 1 ⇒. 2. T (n) = 5T (n/2) +  (n³) vs. n³ sol.) Now lg 5 +  = 3 for some constant  > 0 Use Case 3 ⇒ T (n) =  (n³) Use Case 3 ⇒ T (n) =  (n³) 3. T (n) = 27T (n/3) +  (n³/ lg n) vs. for any k ≥ 0. vs. for any k ≥ 0. sol) Cannot use the master method.

Homework 4.1-3,

Class Exercise Pp.85 Problem 4-1 a, c, f, h