1 How to Multiply Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. integers, matrices, and polynomials.

Slides:



Advertisements
Similar presentations
CS Divide and Conquer/Recurrence Relations1 Divide and Conquer.
Advertisements

A simple example finding the maximum of a set S of n numbers.
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.
Strassen's Matrix Multiplication Sibel KIRMIZIGÜL.
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. Problem Reduction Dr. M. Sakalli Marmara Unv, Levitin ’ s notes.
Introduction to Algorithms Jiafen Liu Sept
Grade School Revisited: How To Multiply Two Numbers Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture.
Lecture 10 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
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
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.
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.
Lecture 4: Divide and Conquer III: Other Applications and Examples Shang-Hua Teng.
Grade School Revisited: How To Multiply Two Numbers Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 16March 4,
Table of Contents Matrices - Multiplication Assume that matrix A is of order m  n and matrix B is of order p  q. To determine whether or not A can be.
Grade School Revisited: How To Multiply Two Numbers Great Theoretical Ideas In Computer Science S. Rudich V. Adamchik CS Spring 2006 Lecture 18March.
1 How to Multiply Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. integers, matrices, and polynomials.
Sec 3.4 & Sec 3.5 Complex Numbers & Complex Zeros
MA/CSSE 473 Day 03 Asymptotics A Closer Look at Arithmetic With another student, try to write a precise, formal definition of “t(n) is in O(g(n))”
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.
Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.
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.
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 3 Prof. Erik Demaine.
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
Complexity 20-1 Complexity Andrei Bulatov Parallel Arithmetic.
Applied Symbolic Computation1 Applied Symbolic Computation (CS 300) Karatsuba’s Algorithm for Integer Multiplication Jeremy R. Johnson.
COMPSCI 102 Introduction to Discrete Mathematics.
4/3/2003CSE More Math CSE Algorithms Euclidean Algorithm Divide and Conquer.
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
Operations with 2x2 matrices IB SL/HL
1 Chapter 4-2 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
ADA: 4.5. Matrix Mult.1 Objective o an extra divide and conquer example, based on a question in class Algorithm Design and Analysis (ADA) ,
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
Copyright © 2015, 2011, 2007 Pearson Education, Inc. 1 1 Chapter 8 Rational Exponents, Radicals, and Complex Numbers.
Lecture 5 Today, how to solve recurrences We learned “guess and proved by induction” We also learned “substitution” method Today, we learn the “master.
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
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.
Divide and Conquer Faculty Name: Ruhi Fatima Topics Covered Divide and Conquer Matrix multiplication Recurrence.
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
3.5 Perform Basic Matrix Operations Add Matrices Subtract Matrices Solve Matric equations for x and y.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 16.
Fractions Addition, Subtraction, Multiplication and Division June 25, 2016June 25, 2016June 25, 2016.
Chapter 4 Divide-and-Conquer
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Chapter 4 Divide-and-Conquer
Great Theoretical Ideas in Computer Science
Algorithms with numbers (1) CISC4080, Computer Algorithms
Applied Symbolic Computation
Algebraic Properties.
Grade School Revisited: How To Multiply Two Numbers
Punya Biswas Lecture 15 Closest Pair, Multiplication
Applied Symbolic Computation
Conjugates Standard form of Complex Numbers
Divide-and-Conquer The most-well known algorithm design strategy:
CSCI 256 Data Structures and Algorithm Analysis Lecture 12
Comments from last time
Topic: Divide and Conquer
Applied Symbolic Computation
Divide-and-Conquer 7 2  9 4   2   4   7
Introduction to Discrete Mathematics
Presentation transcript:

1 How to Multiply Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. integers, matrices, and polynomials

2 Complex Multiplication Complex multiplication. (a + bi) (c + di) = x + yi. Grade-school. x = ac - bd, y = bc + ad. Q. Is it possible to do with fewer multiplications? 4 multiplications, 2 additions

3 Complex Multiplication Complex multiplication. (a + bi) (c + di) = x + yi. Grade-school. x = ac - bd, y = bc + ad. Q. Is it possible to do with fewer multiplications? A. Yes. [Gauss] x = ac - bd, y = (a + b) (c + d) - ac - bd. Remark. Improvement if no hardware multiply. 4 multiplications, 2 additions 3 multiplications, 5 additions

5.5 Integer Multiplication

5 Addition. Given two n -bit integers a and b, compute a + b. Grade-school.  (n) bit operations. Remark. Grade-school addition algorithm is optimal. Integer Addition

6 Integer Multiplication Multiplication. Given two n -bit integers a and b, compute a  b. Grade-school.  (n 2 ) bit operations. Q. Is grade-school multiplication algorithm optimal? 

7 To multiply two n -bit integers a and b : Multiply four ½ n -bit integers, recursively. n Add and shift to obtain result. Ex. Divide-and-Conquer Multiplication: Warmup a = b = a1a1 a0a0 b1b1 b0b0

8 Recursion Tree n 4(n/2) 16(n/4) 4 k (n / 2 k ) 4 lg n (1) 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)... T(n/2)...

9 To multiply two n -bit integers a and b : Add two ½ n bit integers. Multiply three ½ n -bit integers, recursively. n Add, subtract, and shift to obtain result. Karatsuba Multiplication

10 To multiply two n -bit integers a and b : Add two ½ n bit integers. Multiply three ½ n -bit integers, recursively. n Add, subtract, and shift to obtain result. Theorem. [Karatsuba-Ofman 1962] Can multiply two n -bit integers in O(n ) bit operations. Karatsuba Multiplication

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

Matrix Multiplication

13 Dot product. Given two length n vectors a and b, compute c = a  b. Grade-school.  (n) arithmetic operations. Remark. Grade-school dot product algorithm is optimal. Dot Product

14 Matrix multiplication. Given two n -by- n matrices A and B, compute C = AB. Grade-school.  (n 3 ) arithmetic operations. Q. Is grade-school matrix multiplication algorithm optimal? Matrix Multiplication

15 Block Matrix Multiplication C 11 A 11 A 12 B 11

16 Matrix Multiplication: Warmup To multiply two n -by- n matrices A and B : Divide: partition A and B into ½ n -by-½ n blocks. Conquer: multiply 8 pairs of ½ n -by-½ n matrices, recursively. Combine: add appropriate products using 4 matrix additions.

17 Fast Matrix Multiplication Key idea. multiply 2 -by- 2 blocks with only 7 multiplications. 7 multiplications. 18 = additions and subtractions.

18 Fast Matrix Multiplication To multiply two n -by- n matrices A and B : [Strassen 1969] Divide: partition A and B into ½ n -by-½ n blocks. Compute: 14 ½ n -by-½ n matrices via 10 matrix additions. Conquer: multiply 7 pairs of ½ n -by-½ n matrices, recursively. Combine: 7 products into 4 terms using 8 matrix additions. Analysis. Assume n is a power of 2. T(n) = # arithmetic operations.