Chapter 4: Divide and Conquer

Slides:



Advertisements
Similar presentations
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Advertisements

Divide-and-Conquer CIS 606 Spring 2010.
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)
5/15/ Algorithms1 Algorithms – Ch4 - Divide & Conquer Recurrences: as we saw in another lecture, the Divide and Conquer approach leads to Recurrence.
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.
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.
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
Recurrence Relations Connection to recursive algorithms Techniques for solving them.
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
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.
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
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.
Recurrences David Kauchak cs161 Summer Administrative Algorithms graded on efficiency! Be specific about the run times (e.g. log bases) Reminder:
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
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.
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.
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.
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
Introduction to Algorithms: Divide-n-Conquer Algorithms
Recursion Ali.
Mathematical Foundations (Solving Recurrence)
Lecture 11. Master Theorem for analyzing Recursive relations
Divide-and-Conquer 6/30/2018 9:16 AM
Analysis of Algorithms
CS 3343: Analysis of Algorithms
CSCE 411 Design and Analysis of Algorithms
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
Advance Analysis of Lecture No 9 Institute of Southern Punjab Multan
Introduction to Algorithms 6.046J
Algorithms and Data Structures Lecture III
Divide-and-Conquer 7 2  9 4   2   4   7
Ch 4: Recurrences Ming-Te Chi
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.
Design and Analysis of Algorithms
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
Divide and Conquer Merge sort and quick sort Binary search
Algorithms and Data Structures Lecture III
Presentation transcript:

Chapter 4: Divide and Conquer

Divide and Conquer

Divide and Conquer (Normally, they can be ignored.)

Divide and Conquer Methods for solving recurrences: Substitution Method: Guess a bound and use Mathematical induction to prove. Master Method: Memorize three cases and use them to solve recurrences of the form: T(n) = a T(n/b) + f(n) Iteration Method: However, it is too easy to make an error in parenthesization, and that recursion trees give a better intuitive idea than iterating the recurrence of how the recurrence progresses. Recursion-tree Method: Converts the recurrence into a tree whose nodes represent the cost incurred at various levels of recursion. We use techniques for bounding summations to solve the recurrence.

The Maximum-subarray problem Consider investing in stock market. You can buy one unit of stock only one time and then sell it at a later date, buying and selling after close of the trading day. Suppose you have a “Cristal Ball” to see the price of the stock in the future. What is your strategy?

The Maximum-subarray problem Should you always buy at the lowest or sell at the highest? Consider: We need to find the nonempty, contiguous subarray of array A whose values have the largest sum.

The Maximum-subarray problem Three possibilities for the location of the maximum-subarray with respect to the midpoint (the divide point):

The Maximum-subarray problem

The Maximum-subarray problem

The Maximum-subarray problem

The Maximum-subarray problem

The Maximum-subarray problem

The Maximum-subarray problem

Strassen’s algorithm for matrix multiplication

Strassen’s algorithm for matrix multiplication

Strassen’s algorithm for matrix multiplication

Strassen’s algorithm for matrix multiplication Note: We can partition matrices without copying entries by instead using index calculations. It would take only constant time, instead of Θ( 𝑛 2 ) time. However, the asymptotic analysis won’t change when we use either technique.

Strassen’s algorithm for matrix multiplication n x n

Strassen’s algorithm for matrix multiplication

Strassen’s algorithm for matrix multiplication

Strassen’s algorithm for matrix multiplication

Strassen’s algorithm for matrix multiplication

Strassen’s algorithm for matrix multiplication To see how these computations work, expand each right-hand side, replacing each Pi with the sub-matrices of A and B that form it, and cancel terms:

Strassen’s algorithm for matrix multiplication

Substitution method 1. Guess the solution. 2. Use induction to find the constants and show that the solution works.

Substitution method

Substitution method

Substitution method

Substitution method

Substitution method Remedy: Subtract off a lower-order term.

Recursion Tree Use to generate a guess. Then verify by substitution method. Consider the recurrence 𝑇 𝑛 =3𝑇 𝑛 4 +𝑐 𝑛 2

Recursion Tree Note: not a complete binary tree. Depth for leftmost branch: Subproblem size for a node at depth i is 1 3 𝑖 𝑛 . Therefore, 1 3 𝑖 𝑛 = 1 → i = log3n Depth for the rigtmost: Subproblem size for a node at depth i is 2 3 𝑖 𝑛 . Therefore, 2 3 𝑖 𝑛 = 1 → i = 𝑙𝑜𝑔 3/2 𝑛

Recursion Tree

Recursion Tree

Recursion Tree

Master Method Let a, b, and k be integers satisfying a ≥ 1, b ≥ 2, and k ≥ 0 n/b can be either floor or ceiling function. Floor: T(0) = u is given Ceiling: T(1) = u is given Examples: T(n) = 4T(n/2) + n  T(n)  ? T(n) = 4T(n/2) + n2  T(n)  ? T(n) = 4T(n/2) + n3  T(n)  ?

Master Method F(n) is polynomially smaller than 𝑛 log 𝑏 𝑎 F(n) is the same size as 𝑛 log 𝑏 𝑎 F(n) is polynomially larger than 𝑛 log 𝑏 𝑎 . It should also satisfy the regularity condition

Master Method F(n) is polynomially smaller than 𝑛 log 𝑏 𝑎 F(n) is the same size as 𝑛 log 𝑏 𝑎 F(n) is polynomially larger than 𝑛 log 𝑏 𝑎 . It should also satisfy the regularity condition

Master Method

Master Method