0% found this document useful (0 votes)
23 views50 pages

Unit - 1

Strassen's algorithm improves on the naive matrix multiplication algorithm by using a "divide and conquer" approach. It recursively breaks the matrices into quarters and uses a novel formula to compute the result with 7 recursive calls rather than 8. This results in an asymptotic runtime of O(N^2.8) rather than O(N^3) for the naive method. The best current methods are even more improved with a runtime of O(N^2.32).

Uploaded by

Raj
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)
23 views50 pages

Unit - 1

Strassen's algorithm improves on the naive matrix multiplication algorithm by using a "divide and conquer" approach. It recursively breaks the matrices into quarters and uses a novel formula to compute the result with 7 recursive calls rather than 8. This results in an asymptotic runtime of O(N^2.8) rather than O(N^3) for the naive method. The best current methods are even more improved with a runtime of O(N^2.32).

Uploaded by

Raj
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/ 50

Unit -1

Strassen Matrix Multiplication


Divide-and-Conquer algorithsm for matrix multiplication

A11 A12 B11 B12 C 11 C12


A= A21 A22 B = B21 B22 C=A×B= C 21 C22
1112 21 22
Formulas for C , C , C , C :

C 11 = A11B11 + A12B21 C 12 = A11B12 + A12B22


C 21 = A21B11 + A22B21 C 22 = A21B12 + A22B22
The First Attempt Straightforward from the formulas above (assuming that N is a power of 2):
MMult(A, B, N)
If N = 1 Output A × B
* Else
11 11 22 22
3. Compute A , B , . . . , A , B % by computing M = N/2
11 11
• X1 ← M M ULT(A , B , N/2)
12 21
• X2 ← M M ULT(A , B , N/2)
11 12
• X3 ← M M ULT(A , B , N/2)
12 22
• X4 ← M M ULT(A , B , N/2)
21 11
• X5 ← M M ULT(A , B , N/2)
22 21
• X6 ← M M ULT(A , B , N/2)
21 12
• X7 ← M M ULT(A , B , N/2)
22 22
• X8 ← M M ULT(A , B , N/2)
11
• C ← X1 + X2
12
• C ← X3 + X4
21
• C ← X5 + X6
22
• C ← X7 + X8
• Output C
• End If
2
Analysis: The operations on line 3 take constant time. The combining cost (lines 12–15) is Θ(N ) (adding
N N N 2
two 2 × 2 matrices takes time 42 = Θ(N )). There are 8 recursive calls (lines 4–11). So let T (N) be the
total number of mathematical operations performed by MMult(A, B, N), then

N 2
T (N) = 8T ( 2 ) + Θ(N )
The Master Theorem gives us
log (8) 3
T (N) = Θ(N 2
) = Θ(N )
3
So this is not an improvement on the “obvious” algorithm given earlier (that uses N operations).
Strassen’s algorithm is based on the following observation:
11 12
C =P5 + P4 − P2 + P6 C =P1 + P2
21 22
C =P3 + P4 C =P1 + P5 − P3 − P7
where
11 12 22
P1 = A (B −B )
11 12 22
P2 = (A + A )B
21 22 11
P3 = (A + A )B
22 21 11
P4 = A (B −B )
11 22 11 22
P5 = (A + A )(B +B )
12 22 21 22
P6 = (A − A )(B +B )
11 21 11 12
P7 = (A − A )(B +B )

11 22
Exercise Verify that C , . . . , C can be computed as above.
The above formulas can be used to compute A × B recursively as follows:
Strassen(A, B)

1. If N = 1 Output A × B
2. Else
11 11 22 22
3. Compute A , B , . . . , A , B % by computing M = N/2
11 12 22
4. P1 ← STRASSEN(A , B − B )
11 12 22
5. P2 ← STRASSEN(A + A , B )
21 22 11
6. P3 ← STRASSEN(A + A , B )
22 21 11
7. P4 ← STRASSEN(A , B − B )
11 22 11 22
8. P5 ← STRASSEN(A + A , B + B )
12 22 21 22
9. P6 ← STRASSEN(A − A , B + B )
11 21 11 12
10. P7 ← STRASSEN(A − A , B + B )
11
11. C ← P5 + P4 − P2 + P6
12
12. C ← P1 + P2
21
13. C ← P3 + P4
22
14. C ← P1 + P5 − P3 − P7
15. Output C
16. End If
2
Analysis: The operations on line 3 take constant time. The combining cost (lines 11–14) is Θ(N ).
There are 7 recursive calls (lines 4–10). So let T (N) be the total number of mathematical operations
performed by Strassen(A, B), then

N 2
T (N) = 7T ( 2 ) + Θ(N )

2
The Master Theorem gives us
log (7) 2.8
T (N) = Θ(N 2
) = Θ(N )
2.32
The best current upper bound for multiplying two matrices of size N × N is O(N ) (by using similar
idea, but instead of dividing a matrix into 4 quarters, people divide them into a bigger number of
submatrices).

You might also like