1 Chapter 4-2 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.

Slides:



Advertisements
Similar presentations
Divide-and-Conquer CIS 606 Spring 2010.
Advertisements

Algorithm Design Methodologies Divide & Conquer Dynamic Programming Backtracking.
DIVIDE AND CONQUER. 2 Algorithmic Paradigms Greedy. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer.
Dr. Deshi Ye Divide-and-conquer Dr. Deshi Ye
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 5 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Introduction to Algorithms Jiafen Liu Sept
1 Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances.
Divide-and-Conquer Matrix multiplication and Strassen’s algorithm Median Problem –In general finding the kth largest element of an unsorted list of numbers.
Lecture 10 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
1 Divide-and-Conquer Divide-and-conquer. n Break up problem into several parts. n Solve each part recursively. n Combine solutions to sub-problems into.
Introduction to Algorithms 6.046J/18.401J L ECTURE 3 Divide and Conquer Binary search Powering a number Fibonacci numbers Matrix multiplication Strassen’s.
CS223 Advanced Data Structures and Algorithms 1 Divide and Conquer Neil Tang 4/15/2010.
Algorithm Design Strategy Divide and Conquer. More examples of Divide and Conquer  Review of Divide & Conquer Concept  More examples  Finding closest.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Chapter 4 Divide-and-Conquer Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Divide-and-Conquer Matrix multiplication and Strassen’s algorithm.
Notes on the analysis of multiplication algorithms.. Dr. M. Sakalli, Marmara University.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Fast Fourier Transform Jean Baptiste Joseph Fourier ( ) These lecture.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Fundamentals of matrices
Warm-up 1.Review notes from Friday. 2.What is the dimension of the matrix below?
1 How to Multiply Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. integers, matrices, and polynomials.
4.2 Operations with Matrices Scalar multiplication.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013 Lecture 12.
Divide-and-Conquer 7 2  9 4   2   4   7
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
MA/CSSE 473 Day 17 Divide-and-conquer Convex Hull Strassen's Algorithm: Matrix Multiplication.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 5 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 3 Prof. Erik Demaine.
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
5.6 Convolution and FFT. 2 Fast Fourier Transform: Applications Applications. n Optics, acoustics, quantum physics, telecommunications, control systems,
Karatsuba’s Algorithm for Integer Multiplication
1 Chapter 4 Divide-and-Conquer. 2 About this lecture Recall the divide-and-conquer paradigm, which we used for merge sort: – Divide the problem into a.
Applied Symbolic Computation1 Applied Symbolic Computation (CS 300) Karatsuba’s Algorithm for Integer Multiplication Jeremy R. Johnson.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
Lecture 5 Today, how to solve recurrences We learned “guess and proved by induction” We also learned “substitution” method Today, we learn the “master.
Introduction: Efficient Algorithms for the Problem of Computing Fibonocci Numbers Prepared by John Reif, Ph.D. Analysis of Algorithms.
Warm Up Perform the indicated operations. If the matrix does not exist, write impossible
EXAMPLE 1 Add and subtract matrices
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 How to Multiply Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. integers, matrices, and polynomials.
Young CS 331 D&A of Algo. Topic: Divide and Conquer1 Divide-and-Conquer General idea: Divide a problem into subprograms of the same kind; solve subprograms.
1 Complete this to a Pfaffian orientation (all internal faces have an odd number of clockwise arcs).
Divide and Conquer Faculty Name: Ruhi Fatima Topics Covered Divide and Conquer Matrix multiplication Recurrence.
3.6 Multiplying Matrices Homework 3-17odd and odd.
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 16.
MA/CSSE 473 Day 14 Strassen's Algorithm: Matrix Multiplication Decrease and Conquer DFS.
Prepared by John Reif, Ph.D.
Introduction to Algorithms: Divide-n-Conquer Algorithms
Chapter 2 Divide-and-Conquer algorithms
Divide-and-Conquer The most-well known algorithm design strategy:
Chapter 4 Divide-and-Conquer
Algorithms with numbers (1) CISC4080, Computer Algorithms
CSCE 411 Design and Analysis of Algorithms
WarmUp 2-3 on your calculator or on paper..
Divide-and-Conquer Divide-and-conquer.
Introduction to Algorithms
CSCI 256 Data Structures and Algorithm Analysis Lecture 12
Topic: Divide and Conquer
1.8 Matrices.
What is the dimension of the matrix below?
1.8 Matrices.
Divide-and-Conquer 7 2  9 4   2   4   7
Presentation transcript:

1 Chapter 4-2 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.

5.5 Integer Multiplication

3 Integer Arithmetic Add. Given two n-digit integers a and b, compute a + b. n O(n) bit operations. Multiply. Given two n-digit integers a and b, compute a × b. n Brute force solution:  (n 2 ) bit operations Add Multiply

4 To multiply two n-digit integers: n Multiply four ½n-digit integers. n Add two ½n-digit integers, and shift to obtain result. Divide-and-Conquer Multiplication: Warmup assumes n is a power of 2 By 4.4 of your textbook

5 To multiply two n-digit integers: n Add two ½n digit integers. n Multiply three ½n-digit integers. n Add, subtract, and shift ½n-digit integers to obtain result. Theorem. [Karatsuba-Ofman, 1962] Can multiply two n-digit integers in O(n ) bit operations. Karatsuba Multiplication AB C A C

6 Karatsuba: Recursion Tree n 3(n/2) 9(n/4) 3 k (n / 2 k ) 3 lg n (2)... T(n) T(n/2) T(n/4) T(2) T(n / 2 k ) T(n/4) T(n/2) T(n/4) T(n/2) T(n/4)...

Matrix Multiplication

8 Matrix multiplication. Given two n-by-n matrices A and B, compute C = AB. Brute force.  (n 3 ) arithmetic operations. Fundamental question. Can we improve upon brute force? Matrix Multiplication

9 Matrix Multiplication: Warmup Divide-and-conquer. n Divide: partition A and B into ½n-by-½n blocks. n Conquer: multiply 8 ½n-by-½n recursively. n Combine: add appropriate products using 4 matrix additions. By 4.4 of your textbook

10 Matrix Multiplication: Key Idea Key idea. multiply 2-by-2 block matrices with only 7 multiplications. n 7 multiplications. n 18 = additions (or subtractions).

11 Fast Matrix Multiplication Fast matrix multiplication. (Strassen, 1969) n Divide: partition A and B into ½n-by-½n blocks. n Compute: 14 ½n-by-½n matrices via 10 matrix additions. n Conquer: multiply 7 ½n-by-½n matrices recursively. n Combine: 7 products into 4 terms using 8 matrix additions. Analysis. n Assume n is a power of 2. n T(n) = # arithmetic operations. Proof is analogous to 4.6 of your textbook

12 Fast Matrix Multiplication in Practice Implementation issues. n Sparsity. n Caching effects. n Numerical stability. n Odd matrix dimensions. n Crossover to classical algorithm around n = 128. Common misperception: "Strassen is only a theoretical curiosity." n Advanced Computation Group at Apple Computer reports 8x speedup on G4 Velocity Engine when n ~ 2,500. n Range of instances where it's useful is a subject of controversy. Remark. Can "Strassenize" Ax=b, determinant, eigenvalues, and other matrix ops.

13 Fast Matrix Multiplication in Theory Q. Multiply two 2-by-2 matrices with only 7 scalar multiplications? A. Yes! [Strassen, 1969] Q. Multiply two 2-by-2 matrices with only 6 scalar multiplications? A. Impossible. [Hopcroft and Kerr, 1971] Q. Two 3-by-3 matrices with only 21 scalar multiplications? A. Also impossible. Q. Two 70-by-70 matrices with only 143,640 scalar multiplications? A. Yes! [Pan, 1980] Decimal wars. n December, 1979: O(n ). n January, 1980: O(n ).

14 Fast Matrix Multiplication in Theory Best known. O(n ) [Coppersmith-Winograd, 1987.] Conjecture. O(n 2+  ) for any  > 0. Caveat. Theoretical improvements to Strassen are progressively less practical.

HOMEWORK (Chapter 4) Prove “ → “ in the following