Matrix Multiplication Algorithms With Better Time Complexity
Matrix Multiplication Algorithms With Better Time Complexity
c11[][] = p5 + p4 - p2 + p6 4 4 4
c12[][] = p1 + p2 4 4 4
c21[][] = p3 + p4 10 c11[1][1] c12[1][1]
c22[][] = p1 + p5 - p3 - p7 8
10 8
c = merge(c11, c12, c21, c22) 10 8
return c c[2][2]
c21[1][1] c22[1][1]
Coppersmith Winograd
Algorithm
Time complexity: O(n2.38)
Year introduced: 1987
1. Start.
Algorithm
3. Choose matrix a[n][1] randomly to which
component will be 0 or 1.
breakdown
4. Calculate M2 * a, M3 * a and then M1 *
(M2 * a) for computing the expression
M1 * (M2 * a) - M3 * a.
7. End.
coppersmithWinograd(M1[][], M2[][], M3[][], n):
double a[n][1]
for i: 0 → n 1 2 2 0 4 4
a[i][1] = random() % 2
double M2a[n][1]
for i: 0 → n
3 4 1 2 10 8
for j: 0 → 1
for k: 0 → n M1[2][2] M2[2][2] M3[2][2]
M2a[i][j] += M2[i][k] * a[k][j]
double M3a[n][1] 0
for i: 0 → n
for j: 0 → 1
for k: 0 → n
M3a[i][j] += M3[i][k] * a[k][j]
1
double M12a[n][1] a[2][1]
for i: 0 → n
for j: 0 → 1
for k: 0 → n
M12a[i][j] += M1[i][k] * M2a[k][j]
0 4 = 4
for i: 0 → n
if M12a[i][0] != M3a[i][0]: return false 2 8 = 8
return true M2a[2][1] M3a[2][1] M12a[2][1]
Conclusion
The journey of minimizing the timing complexity of matrix multiplication
algorithm has brought us from O(n3) to O(n2.38) up to now and may continue
to be improved further in the future.