Richard Anderson Lecture 12 Recurrences and Divide and Conquer

Slides:



Advertisements
Similar presentations
A simple example finding the maximum of a set S of n numbers.
Advertisements

1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 4 Instructor: Paul Beame TA: Gidon Shavit.
Strassen's Matrix Multiplication Sibel KIRMIZIGÜL.
Divide-and-Conquer Matrix multiplication and Strassen’s algorithm Median Problem –In general finding the kth largest element of an unsorted list of numbers.
1 Divide-and-Conquer CSC401 – Analysis of Algorithms Lecture Notes 11 Divide-and-Conquer Objectives: Introduce the Divide-and-conquer paradigm Review the.
Introduction to Algorithms 6.046J/18.401J L ECTURE 3 Divide and Conquer Binary search Powering a number Fibonacci numbers Matrix multiplication Strassen’s.
Lecture 2: Divide and Conquer algorithms Phan Thị Hà Dương
CS223 Advanced Data Structures and Algorithms 1 Divide and Conquer Neil Tang 4/15/2010.
Recursion & Merge Sort Introduction to Algorithms Recursion & Merge Sort CSE 680 Prof. Roger Crawfis.
Algorithms Recurrences Continued The Master Method.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
CSE 421 Algorithms Richard Anderson Lecture 12 Recurrences.
Divide-and-Conquer Matrix multiplication and Strassen’s algorithm.
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.
CSE 421 Algorithms Richard Anderson Lecture 13 Divide and Conquer.
Recurrence Examples.
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions Analysis of.
CSE 421 Algorithms Richard Anderson Lecture 11 Recurrences.
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions BIL741: Advanced.
Divide-and-Conquer 7 2  9 4   2   4   7
MA/CSSE 473 Day 17 Divide-and-conquer Convex Hull Strassen's Algorithm: Matrix Multiplication.
Divide-and-Conquer Dr. B C Dhara Department of Information Technology Jadavpur University.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 3 Prof. Erik Demaine.
CS223 Advanced Data Structures and Algorithms 1 Sorting and Master Method Neil Tang 01/21/2009.
Data Structures and Algorithms A. G. Malamos
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.
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
1 Algorithms CSCI 235, Fall 2015 Lecture 6 Recurrences.
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.
CSEP 521 Applied Algorithms Richard Anderson Winter 2013 Lecture 4.
Master Method Some of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Divide and Conquer (Part II) Multiplication of two numbers Let U = (u 2n-1 u 2n-2 … u 1 u 0 ) 2 and V = (v 2n-1 v 2n-2 …v 1 v 0 ) 2, and our goal is to.
Divide and Conquer Faculty Name: Ruhi Fatima Topics Covered Divide and Conquer Matrix multiplication Recurrence.
CSE 421 Algorithms Richard Anderson Lecture 13 Recurrences, Part 2.
Introduction to Algorithms: Divide-n-Conquer Algorithms
Introduction to Algorithms: Recurrences
Chapter 4: Divide and Conquer
Chapter 4 Divide-and-Conquer
Richard Anderson Lecture 14 Divide and Conquer
CSCE 411 Design and Analysis of Algorithms
Punya Biswas Lecture 15 Closest Pair, Multiplication
Richard Anderson Lecture 13 Recurrences and Divide and Conquer
Divide-and-Conquer 7 2  9 4   2   4   7
Richard Anderson Lecture 11 Recurrences
Richard Anderson Lecture 13 Divide and Conquer
Richard Anderson Lecture 11 Minimum Spanning Trees
CS 3343: Analysis of Algorithms
Richard Anderson Lecture 13 Recurrences, Part 2
CSE 2010: Algorithms and Data Structures
Introduction to Algorithms
Divide-and-Conquer 7 2  9 4   2   4   7
Divide and Conquer Neil Tang 4/24/2008
Lecture 15, Winter 2019 Closest Pair, Multiplication
Richard Anderson Lecture 14 Divide and Conquer
Richard Anderson Lecture 13, Winter 2019 Recurrences, Part 2
Richard Anderson Lecture 14, Winter 2019 Divide and Conquer
Richard Anderson Lecture 14 Divide and Conquer
Algorithms CSCI 235, Spring 2019 Lecture 6 Recurrences
Divide-and-Conquer 7 2  9 4   2   4   7
Lecture 15 Closest Pair, Multiplication
Richard Anderson Lecture 12, Winter 2019 Recurrences
Algorithms CSCI 235, Spring 2019 Lecture 8 Recurrences III
Richard Anderson Lecture 12 Recurrences
Richard Anderson Lecture 13 Divide and Conquer
Presentation transcript:

Richard Anderson Lecture 12 Recurrences and Divide and Conquer CSE 421 Algorithms Richard Anderson Lecture 12 Recurrences and Divide and Conquer

Divide and Conquer

Recurrence Examples T(n) = 2 T(n/2) + cn T(n) = T(n/2) + cn O(n log n) T(n) = T(n/2) + cn O(n) More useful facts: logkn = log2n / log2k k log n = n log k

T(n) = aT(n/b) + f(n)

Recursive Matrix Multiplication Multiply 2 x 2 Matrices: | r s | | a b| |e g| | t u| | c d| | f h| r = ae + bf s = ag + bh t = ce + df u = cg + dh A N x N matrix can be viewed as a 2 x 2 matrix with entries that are (N/2) x (N/2) matrices. The recursive matrix multiplication algorithm recursively multiplies the (N/2) x (N/2) matrices and combines them using the equations for multiplying 2 x 2 matrices =

Recursive Matrix Multiplication How many recursive calls are made at each level? How much work in combining the results? What is the recurrence?

What is the run time for the recursive Matrix Multiplication Algorithm? Recurrence:

T(n) = 4T(n/2) + cn

T(n) = 2T(n/2) + n2

T(n) = 2T(n/2) + n1/2

Recurrences Three basic behaviors Dominated by initial case Dominated by base case All cases equal – we care about the depth

Solve by unrolling T(n) = n + 5T(n/2) Answer: nlog(5/2)

What you really need to know about recurrences Work per level changes geometrically with the level Geometrically increasing (x > 1) The bottom level wins Geometrically decreasing (x < 1) The top level wins Balanced (x = 1) Equal contribution

Classify the following recurrences (Increasing, Decreasing, Balanced) T(n) = n + 5T(n/8) T(n) = n + 9T(n/8) T(n) = n2 + 4T(n/2) T(n) = n3 + 7T(n/2) T(n) = n1/2 + 3T(n/4)

Strassen’s Algorithm Multiply 2 x 2 Matrices: | r s | | a b| |e g| | t u| | c d| | f h| Where: p1 = (b + d)(f + g) p2= (c + d)e p3= a(g – h) p4= d(f – e) p5= (a – b)h p6= (c – d)(e + g) p7= (b – d)(f + h) = r = p1 + p4 – p5 + p7 s = p3 + p5 t = p2 + p5 u = p1 + p3 – p2 + p7

Recurrence for Strassen’s Algorithms T(n) = 7 T(n/2) + cn2 What is the runtime?

BFPRT Recurrence T(n) <= T(3n/4) + T(n/5) + 20 n What bound do you expect?