1 of 15

Strassen’s Matrix Multiplication�

  • Given two square matrices A and B of size

N x N each, find their multiplication matrix.

Amity School of Engineering & Technology

2 of 15

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

3 of 15

  • Time Complexity of above method is O(N3).

Amity School of Engineering & Technology

4 of 15

Divide and Conquer

  • Following is simple Divide and Conquer method to multiply two square matrices.�

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

5 of 15

Amity School of Engineering & Technology

6 of 15

  • In the above method, we do 8 multiplications for matrices of size N/2 x N/2 and 4 additions. Addition of two matrices takes O(N2) time. So the time complexity can be written as

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

7 of 15

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

8 of 15

Amity School of Engineering & Technology

9 of 15

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

10 of 15

C11 = P + S - T+ V�C12 = R+ T �C21 = Q + S �C22 = P + R - Q + U

Amity School of Engineering & Technology

11 of 15

Time Complexity of Strassen’s Method

  • Addition and Subtraction of two matrices takes O(N2) time. So time complexity can be written as

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

12 of 15

Problem-1

Amity School of Engineering & Technology

13 of 15

Answer

Amity School of Engineering & Technology

14 of 15

Problem-2

Amity School of Engineering & Technology

15 of 15

Answer

Amity School of Engineering & Technology