4.1 Strassens Algorithm
4.1 Strassens Algorithm
Step 1 :
Add corresponding elements and store the result in the corresponding element of matrix C.
Step 2:
Subtract corresponding elements and store the result in the corresponding element of matrix C.
Step 3
If the size of the matrices is 1x1, perform a simple multiplication and store the result in the
corresponding element of matrix C.
Otherwise, perform the following steps for each quadrant of the matrices:
Compute seven products (P1 to P7) using recursive calls to strassen and specific additions and
subtractions.
The recursive calls continue until matrices of size 1x1 are reached.
Step 4:
Iterate through each element of the matrix and print its value.
Step 5:
main Function:
Print the original matrices (A and B) and the result matrix (C).
Code:
#include <stdio.h>
if (n == 1) {
return;
int newSize = n / 2;
int A11[newSize][newSize], A12[newSize][newSize], A21[newSize][newSize], A22[newSize]
[newSize];
A11[i][j] = A[i][j];
B11[i][j] = B[i][j];
C[i][j] = C11[i][j];
printf("%d\t", mat[i][j]);
printf("\n");
int main() {
int A[4][4] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
};
int B[4][4] = {
};
// Resultant matrix C
int C[4][4];
strassen(n, A, B, C);
printf("Matrix A:\n");
printMatrix(n, A);
printf("\nMatrix B:\n");
printMatrix(n, B);
printMatrix(n, C);
return 0;
Output:
Matrix A:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Matrix B:
17 18 19 20
21 22 23 24
25 26 27 28
29 30 31 32