Skip to content

Commit 83fc7a8

Browse files
Added Comments
1 parent 8674dcf commit 83fc7a8

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Arrays/Strassen's_Algo.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ int main(){
33
int mat1[2][2], mat2[2][2], mat3[2][2], i, j;
44
int a, b, c, d , e, f, g;
55

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
77
for(i = 0;i < 2; i++)
88
{
99
for(j = 0;j < 2; j++)
@@ -12,7 +12,7 @@ int main(){
1212
}
1313
}
1414

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
1616
for(i = 0; i < 2; i++)
1717
{
1818
for(j = 0;j < 2; j++)
@@ -40,15 +40,22 @@ int main(){
4040
}
4141
printf("\n");
4242
}
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]);
4550
b= (mat1[1][0] + mat1[1][1]) * mat2[0][0];
4651
c= mat1[0][0] * (mat2[0][1] - mat2[1][1]);
4752
d= mat1[1][1] * (mat2[1][0] - mat2[0][0]);
4853
e= (mat1[0][0] + mat1[0][1]) * mat2[1][1];
4954
f= (mat1[1][0] - mat1[0][0]) * (mat2[0][0]+mat2[0][1]);
5055
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
5157

58+
//Calculate the elements of matrix 3, The resultant matrix mat3[i][j]
5259
mat3[0][0] = a + d- e + g;
5360
mat3[0][1] = c + e;
5461
mat3[1][0] = b + d;

0 commit comments

Comments
 (0)