Strassen’s Matrix Multiplication�
N x N each, find their multiplication matrix.
Amity School of Engineering & Technology
Naive Method
void multiply(int A[][N], int B[][N], int C[][N])
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
C[i][j] = 0;
for (int k = 0; k < N; k++)
{
C[i][j] += A[i][k]*B[k][j];
}
}
}
}
Amity School of Engineering & Technology
Amity School of Engineering & Technology
Divide and Conquer
Divide matrices A and B in 4 sub-matrices of size N/2 x N/2 as shown in the below diagram.
�
Amity School of Engineering & Technology
Amity School of Engineering & Technology
T(N) = 8T(N/2) + O(N2)
time complexity of above method is O(N3) which is unfortunately same as the above naive method.
Amity School of Engineering & Technology
In the above divide and conquer method, the main component for high time complexity is 8 recursive calls. The idea of Strassen’s method is to reduce the number of recursive calls to 7. Strassen’s method is similar to above simple divide and conquer method in the sense that this method also divide matrices to sub-matrices of size N/2 x N/2 as shown in the above diagram, but in Strassen’s method, the four sub-matrices of result are calculated using following formulae.
Amity School of Engineering & Technology
Amity School of Engineering & Technology
P = (A11+ A22) *(B11+B22) �Q = (A21 + A22) * B11 �R = A11 * (B12 - B22) �S = A22 * (B21 - B11) �T= (A11 + A12) * B22 �U = (A21 - A11) * (B11 + B12) �V= (A12 - A22) * (B21 + B22)
Amity School of Engineering & Technology
C11 = P + S - T+ V�C12 = R+ T �C21 = Q + S �C22 = P + R - Q + U
Amity School of Engineering & Technology
Time Complexity of Strassen’s Method
T(N) = 7T(N/2) + O(N2)
time complexity of above method is O(Nlg7) which is approximately O(N2.8074)
Amity School of Engineering & Technology
Problem-1
Amity School of Engineering & Technology
Answer
Amity School of Engineering & Technology
Problem-2
Amity School of Engineering & Technology
Answer
Amity School of Engineering & Technology