Ch 4: Recurrences Ming-Te Chi

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.
A simple example finding the maximum of a set S of n numbers.
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.
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.
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.
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.
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)
Unit 1. Sorting and Divide and Conquer. Lecture 1 Introduction to Algorithm and Sorting.
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 Algorithms
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.
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.
Chapter 4. Recurrences. Outline Offers three methods for solving recurrences, that is for obtaining asymptotic bounds on the solution In the substitution.
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.
1 Algorithms CSCI 235, Fall 2015 Lecture 6 Recurrences.
Foundations II: Data Structures and Algorithms
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 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.
Equal costs at all levels
Recursion Ali.
Mathematical Foundations (Solving Recurrence)
Lecture 11. Master Theorem for analyzing Recursive relations
Divide-and-Conquer 6/30/2018 9:16 AM
Unit 1. Sorting and Divide and Conquer
Chapter 4: Divide and Conquer
Lecture 4 Divide-and-Conquer
Analysis of Algorithms
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
Advance Analysis of Lecture No 9 Institute of Southern Punjab Multan
Algorithms and Data Structures Lecture III
Divide-and-Conquer 7 2  9 4   2   4   7
CS 3343: Analysis of Algorithms
Divide and Conquer (Merge Sort)
Divide-and-Conquer 7 2  9 4   2   4   7
Ack: Several slides from Prof. Jim Anderson’s COMP 202 notes.
Analysis of Algorithms
Introduction To Algorithms
Algorithms Recurrences.
Algorithms CSCI 235, Spring 2019 Lecture 6 Recurrences
Divide-and-Conquer 7 2  9 4   2   4   7
Quicksort Quick sort Correctness of partition - loop invariant
Algorithms and Data Structures Lecture III
Presentation transcript:

Ch 4: Recurrences Ming-Te Chi Algorithms Ch 4: Recurrences Ming-Te Chi Ch4 Recurrences

Recurrences When an algorithm contains a recursive call to itself, its running time can often described by a recurrence. A recurrence is an equation or inequality that describes a function in terms of its value of smaller inputs. Ch4 Recurrences

Recurrences─examples Summation Factorial Ch4 Recurrences

Recurrences─examples Summation Factorial Ch4 Recurrences

Termination conditions (boundary conditions) Summation Factorial Ch4 Recurrences

Recurrences─CS oriented examples Fibonacci number Merge sort Ch4 Recurrences

Influence of the boundary conditions Fibonacci number Merge sort Ch4 Recurrences

Recurrences Substitution method Recursion-tree method Master method Ch4 Recurrences

Technicalities Neglect certain technical details when stating and solving recurrences. A good example of a detail that is often glossed over is the assumption of integer arguments to functions. Boundary conditions is ignored. Omit floors, ceilings. Ch4 Recurrences

The maximum-subarray problem Ch4 Recurrences

Ch4 Recurrences

Ch4 Recurrences

Matrix multiplication Ch4 Recurrences

A simple divide-and-conquer algorithm Ch4 Recurrences

* Partition problem: Index calculation vs copy entries Ch4 Recurrences

Strassen’s method Ch4 Recurrences

Ch4 Recurrences

The substitution method: Mathematical induction The substitution method for solving recurrence has two steps: 1. Guess the form of the solution. 2. Use mathematical induction to find the constants and show that the solution works. Powerful but can be applied only in cases when it is easy to guess the form of solution. Ch4 Recurrences

Can be used to establish either upper bound or lower bound on a recurrence. Ch4 Recurrences

General principle of the Mathematical Induction True for the trivial case, problem size =1. If it is true for the case of problem at step k, we can show that it is true for the case of problem at step k+1. Ch4 Recurrences

Example Determine the upper bound on the recurrence (We may omit the initial condition later.) Guess Prove for some c > 0. Ch4 Recurrences

Inductive hypothesis: assume this bound holds for The recurrence implies Ch4 Recurrences

Initial condition However Ch4 Recurrences

Making a good guess We guess Making guess provides loose upper bound and lower bound. Then improve the gap. Ch4 Recurrences

Ch4 Recurrences

Ch4 Recurrences

Subtleties Guess Assume  However, assume Ch4 Recurrences

Avoiding pitfalls Assume Hence (WRONG!) You cannot find such a c.   (WRONG!) You cannot find such a c. Ch4 Recurrences

Changing variables Ch4 Recurrences

4.4 the Recursion-tree method Ch4 Recurrences

Ch4 Recurrences

Subproblem size for a node at depth i Total level of tree Number of nodes at depth i Cost of each node at depth i Total cost at depth i Last level, depth , has nodes Ch4 Recurrences

Prove of We conclude, Ch4 Recurrences

The cost of the entire tree Ch4 Recurrences

Ch4 Recurrences

Substitution method We want to Show that T(n) ≤ dn2 for some constant d > 0. Using the same constant c > 0 as before, we have Where the last step holds as long as d (16/13)c. Ch4 Recurrences

Ch4 Recurrences

Subproblem size for a node at depth i Total level of tree Ch4 Recurrences

substitution method As long as d  c/(lg3 – (2/3)). Ch4 Recurrences

4.5 Master method Master Theorem Ch4 Recurrences

Remarks 1: In the first case, f(n) must be polynomailly smaller than That is, f(n) must be asymptotically smaller than by a factor of Similarly, in the third case, f(n) must be polynomailly larger than Also, the condition must be hold. Ch4 Recurrences

Remarks 2: The three cases in the master theorem do not cover all the possibilities. There is a gap between cases 1 and 2 when f(n) is smaller than but not polynomailly smaller. Similarly, there is a gap between cases 2 and 3 when f(n) is larger than but not polynomailly larger (or the additional condition does not hold.) Ch4 Recurrences

Example 1: Ch4 Recurrences

Example 2: Ch4 Recurrences

Example 3: Ch4 Recurrences

Example 4: Ch4 Recurrences

Example 5: Ch4 Recurrences

Remarks 3: The master theory does not apply to the recurrence even though it has the proper form: a = 2, b=2, f(n)= n lgn, and It might seem that case 3 should apply, since f(n)= n lgn is asymptotically larger than But it is not polynomially larger. Ch4 Recurrences

Remarks 3 (continue) However, the master method augments the conditions Case 2 can be applied. Ch4 Recurrences

Example 6: Ch4 Recurrences

Example 7: Ch4 Recurrences

Ch4 Recurrences

Ch4 Recurrences