0% found this document useful (0 votes)
119 views4 pages

Divide-And-Conquer (CLRS 4.2) : Matrix Multiplication

The document describes the divide-and-conquer algorithm for matrix multiplication. It explains how to divide the problem into smaller subproblems by breaking the matrices into smaller square submatrices. Strassen's algorithm improves upon the naive divide-and-conquer approach by computing certain matrix combinations recursively in order to reduce the number of recursive calls from 8 to 7, resulting in a more efficient running time of O(n^2.81) compared to O(n^3) for the straightforward approach.

Uploaded by

Rajeev Ranjan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views4 pages

Divide-And-Conquer (CLRS 4.2) : Matrix Multiplication

The document describes the divide-and-conquer algorithm for matrix multiplication. It explains how to divide the problem into smaller subproblems by breaking the matrices into smaller square submatrices. Strassen's algorithm improves upon the naive divide-and-conquer approach by computing certain matrix combinations recursively in order to reduce the number of recursive calls from 8 to 7, resulting in a more efficient running time of O(n^2.81) compared to O(n^3) for the straightforward approach.

Uploaded by

Rajeev Ranjan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Divide-and-conquer

(CLRS 4.2)

It’s a powerful technique for solving problems:


Divide-and-Conquer (Input: Problem P)

To Solve P:

1. Divide P into smaller problems P1 , P2

2. Conquer by solving the (smaller) subproblems recursively.

3. Combine solutions to P1 , P2 into solution for P.

Matrix Multiplication
 Y be two n × n matrices
Let X and 

 x11 x12 · · · x1n 
 x21 x22 · · · x1n 

 

 
X= x31 x32 · · · x1n
··· ··· ··· ··· 

 

 

 
xn1 xn2 · · · xnn
 
We want to compute Z = X · Y , where zij = nk=1 Xik · Ykj
P

Problem: Given two matrices of size n by n, come up with an algorithm to compute the product.

• The straightfoward method uses ⇒ n2 · n = Θ(n3 ) operations

• Can we do better? That is, is it possible to multiply two matrices faster than Θ(n3 )?

• This was an open problem for a long time... until Strassen came up with an algorithm in
1969. The idea is to use divide-and-conquer.

Matrix multiplication with divide-and-conquer


• Let’s imagine that n is a power of two. We can view each matrix as consisting of 2x2=4
n/2-by-n/2 matrices.
( ) ( )
A B E F
X= ,Y =
C D G H

1
• Then we see that their product X · Y can be written as:
( ) ( ) ( )
A B E F (A · E + B · G) (A · F + B · H)
· =
C D G H (C · E + D · G) (C · F + D · H)

• The above naturally leads to divide-and-conquer solution:

– Divide X and Y into 8 sub-matrices A, B, C, D, E, F, G, H.


– Compute 8 n/2-by-n/2 matrix multiplications recursively.
– Combine results (by doing 4 matrix additions) and copy the results into Z.

• ANALYSIS: Running time of algorithm is given by T (n) = 8T (n/2) + Θ(n2 ) ⇒ T (n) = Θ(n3 )

• Cool idea, but not so cool result......since we already discussed a (simpler/naive) O(n3 ) algo-
rithm!

• Can we do better?

Strassen’s divide-and-conquer
• Strassen’s algorithm is based on the following observation:
The recurrence
T (n) = 8T (n/2) + Θ(n2 ) ⇒ T (n) = Θ(n3 )

while the recurrence

T (n) = 7T (n/2) + Θ(n2 ) ⇒ T (n) = Θ(nlg 7 )

• Strassen foud a way to compute only 7 products of n/2-by-n/2 matrices

• With same notation as before, we define the following 7 n/2-by-n/2 matrices:

S1 = (B − D) · (G + H)
S2 = (A + D) · (E + H)
S3 = (A − C) · (E + F )
S4 = (A + B) · H
S5 = A · (F − H)
S6 = D · (G − E)
S7 = (C + D) · E

• Strassen observed that we can write the product Z as:


( ) ( ) ( )
A B E F (S1 + S2 − S4 + S6 ) (S4 + S5 )
Z= · =
C D G H (S6 + S7 ) (S2 + S3 + S5 − S7 )

2
• For e.g. let’s test that S6 + S7 is really C · E + D · G

S6 + S7 = D · (G − E) + (C + D) · E
= DG − DE + CE + DE
= DG + CE

• This leads to a divide-and-conquer algorithm:

– Divide X and Y into 8 sub-matrices A, B, C, D, E, F, G, H.


– Compute S1 , S2 , S3 , ..., S7 . This involves 10 matrix additions and 7 multiplications re-
cursively.
– Compute S1 + S2 − S4 + S6 , ... and copy them in Z. This step involves only addi-
tions/subtractions of n/2-by-n/2 matrices.

• ANALYSIS: T (n) = 7T (n/2) + Θ(n2 ), with solution O(nlg 7 ).

• Lets solve the recurrence using the iteration method

T (n) = 7T (n/2) + n2
n n
= n2 + 7(7T ( 2 ) + ( )2 )
2 2
2 7 2 2 n
= n + ( 2 )n + 7 T ( 2 )
2 2
7 2 n n
= n + ( 2 )n + 7 (7T ( 3 ) + ( 2 )2 )
2 2
2 2 2
7 7 n
= n2 + ( 2 )n2 + ( 2 )2 · n2 + 73 T ( 3 )
2 2 2
7 2 7 2 2 7 3 2 7
= n + ( 2 )n + ( 2 ) n + ( 2 ) n .... + ( 2 )log n−1 n2 + 7log n
2
2 2 2 2
logX
n−1
7 i 2
= ( ) n + 7log n
i=0
22
7 log n−1
= n2 · Θ(( ) ) + 7log n
22
7log n
= n2 · Θ( 2 log n ) + 7log n
(2 )
7log n
= n2 · Θ( 2 ) + 7log n
n
log n
= Θ(7 )

– Now we have the following:


log7 n
7log n = 7 log7 2
= (7log7 n )(1/ log7 2)

3
= n(1/ log7 2)
log2 7
= n log2 2
= nlog 7

So the solution is T (n) = Θ(nlg 7 ) = Θ(n2.81... )

• Note:

– We are ’hiding’ a much bigger constant in Θ() than before.


– Currently best known bound is O(n2.376.. ) (Coppersmith and Winograd’78).
– Lower bound is (trivially) Ω(n2 ).
– Big open problem!!
– Strassen’s algorithm has been found to be efficient in practice once n is large enough.
For small values of n the straightforward cubic algorithm is used instead. The crossover
point where Strassen becomes more efficient depends from system to system.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy