@@ -3,7 +3,7 @@ int main(){
3
3
int mat1 [2 ][2 ], mat2 [2 ][2 ], mat3 [2 ][2 ], i , j ;
4
4
int a , b , c , d , e , f , g ;
5
5
6
- printf ("Enter the elements of first matrix:\n" ); //matrix 1
6
+ printf ("Enter the elements of first matrix:\n" ); //Input elements for matrix 1
7
7
for (i = 0 ;i < 2 ; i ++ )
8
8
{
9
9
for (j = 0 ;j < 2 ; j ++ )
@@ -12,7 +12,7 @@ int main(){
12
12
}
13
13
}
14
14
15
- printf ("Enter the elements of second matrix:\n" ); //matrix 2
15
+ printf ("Enter the elements of second matrix:\n" ); // Input elements for matrix 2
16
16
for (i = 0 ; i < 2 ; i ++ )
17
17
{
18
18
for (j = 0 ;j < 2 ; j ++ )
@@ -40,15 +40,22 @@ int main(){
40
40
}
41
41
printf ("\n" );
42
42
}
43
- //reduced eight times Time Complexity to Seven Times
44
- a = (mat1 [0 ][0 ] + mat1 [1 ][1 ]) * (mat2 [0 ][0 ] + mat2 [1 ][1 ]);
43
+
44
+ //reduced eight times Time Complexity to Seven Times i.e T(N) = 7T(N/2) + O(N^2)
45
+
46
+ // Compexity: before O(n^3) when used Standard Matrix Multiplication , now :O(n^2.808) when used Strassen's Algorithm
47
+
48
+ //Now we can calculate the product of mat1[i][j] and mat2[i][j] with the following formulas:
49
+ a = (mat1 [0 ][0 ] + mat1 [1 ][1 ]) * (mat2 [0 ][0 ] + mat2 [1 ][1 ]);
45
50
b = (mat1 [1 ][0 ] + mat1 [1 ][1 ]) * mat2 [0 ][0 ];
46
51
c = mat1 [0 ][0 ] * (mat2 [0 ][1 ] - mat2 [1 ][1 ]);
47
52
d = mat1 [1 ][1 ] * (mat2 [1 ][0 ] - mat2 [0 ][0 ]);
48
53
e = (mat1 [0 ][0 ] + mat1 [0 ][1 ]) * mat2 [1 ][1 ];
49
54
f = (mat1 [1 ][0 ] - mat1 [0 ][0 ]) * (mat2 [0 ][0 ]+ mat2 [0 ][1 ]);
50
55
g = (mat1 [0 ][1 ] - mat1 [1 ][1 ]) * (mat2 [1 ][0 ]+ mat2 [1 ][1 ]);
56
+ //Now with a,b,c,d,e,f,g which are the submatrices of size N/2*N/2
51
57
58
+ //Calculate the elements of matrix 3, The resultant matrix mat3[i][j]
52
59
mat3 [0 ][0 ] = a + d - e + g ;
53
60
mat3 [0 ][1 ] = c + e ;
54
61
mat3 [1 ][0 ] = b + d ;
0 commit comments