Professional Documents
Culture Documents
Lecture 3
( Divide-and-Conquer Algorithms:
Matrix Multiplication )
Rezaul A. Chowdhury
Department of Computer Science
SUNY Stony Brook
Fall 2012
Iterative Matrix Multiplication
n
zij = ∑x
k =1
ik y kj
4. for k ← 1 to n do
5. Z[ i ][ j ] ← Z[ i ][ j ] + X[ i ][ k ] ⋅ Y[ k ][ j ]
Recursive ( Divide & Conquer ) Matrix Multiplication
Z X Y
n/2 n/2 n/2
n n n
n/2
= n
n
Recursive ( Divide & Conquer ) Matrix Multiplication
Rec-MM ( X, Y ) { X and Y are n × n matrices,
where n = 2k for integer k ≥ 0 }
9. endif
10. return Z
X11 X12 X21 X22 X11 X12 X21 X22 X11 X12 X21 X22
Y11 Y11 Y11 + _
Y21 Y21 Y21
Y12 +_ Y12 Y12 + _
Y22 Y22 ++ Y22
= ×
Z21 Z22 X21 X22 Y21 Y22
=
X21 Y11 + X22 Y21 X21 Y12 + X22 Y22
( Pd1 - Pr1 )
Pr1 + P11
– ( P22 – Pc2 )
= ( Pd1 – Pr2 )
Pr2 – P22
+ ( P11 – Pc1 )
Strassen’s Matrix Multiplication
Z11
Y21 + +
Y12
Y22 __ + _ + +
X11 X12 X21 X22
Y11
Y21
Z12
_+
Y12
Y22 ++
X11 X12 X21 X22
Y11
_ ++
Z21
Y21 +
Y12
Y22
Sums:
Running Time:
Products:
Θ 1 , 1,
∙
∙
7 Θ
, .
∙
∙
2
∙
∙
Θ !"#$ % Ο
.&
∙
Deriving Strassen’s Algorithm
' ( 0 0 0
' ( 0 1 ) * 0 0 -
) * - ⇒ 0 0 ' ( 1
0 0 ) * .
2
, / 3
' 0 '
' ( -
'( ( -
(C) 2
' ( 0 0 0 0 0 0 0
0 0 0 0 0 *( 0 *) *(
∆
' ( ' ) 0 ' ) 0 0 0 0 0
0 0 0 0 0 0 0 * )
5678 C :
;<=> ? 5678 D :
;<=> ?
Algorithms for Multiplying Two n×
×n Matrices
A recursive algorithm based on multiplying two I J I matrices
using K multiplications will yield an Ο !"#L M algorithm.
To beat Strassen’s algorithm: log Q K R log
7⇒ K R I!"#$ % .
So, for a 3 J 3 matrix, we must have: K R 3!"#$ % R 22.
But the best known algorithm uses 23 multiplications!
Inventor Year Complexity
Classical ― Θ
Volker Strassen 1968 Θ
.&E%
Victor Pan
( multiply two 70 × 70 matrices using 1978 Θ
.%FG
143,640 multiplications )
Θ
.%%
Don Coppersmith & Shmuel Winograd
1990
( arithmetic progressions )
Andrew Stothers 2010 Θ
.%H
Virginia Williams 2011 Θ
.%
%