Professional Documents
Culture Documents
Strassen Matrix Multiplication: Under The Guidance of
Strassen Matrix Multiplication: Under The Guidance of
Submitted by
Mrs. K. Subha
(Assistant Professor, Department of Computer Science andEngineering)
PROBLEM STATEMENT
Hence, the primary objective of this project is to delve deeply into the Strassen
algorithm within the framework of the "Design and Analysis of Algorithms" course.
This endeavor involves understanding the theoretical underpinnings of the Strassen
algorithm, implementing it in code, and rigorously evaluating its performance
characteristics. Through comprehensive performance analysis and complexity
assessment, we aim to ascertain the practical advantages and limitations of the
Strassen algorithm compared to traditional matrix multiplication methods.
Furthermore, this project seeks to explore the potential applications of the Strassen
algorithm in various domains, including but not limited to scientific computing, image
processing, and machine learning. By investigating its efficacy in real-world contexts
and addressing scalability challenges inherent in conventional matrix multiplication,
we aim to contribute to the ongoing discourse in algorithmic optimization and
computational efficiency.
ALGORITHM
1. Input Matrices: Given two input matrices AA and BB, each of size n×nn×n.
2. Base Case Check: If nn is a small value (e.g., n≤2n≤2), perform standard matrix
multiplication using the conventional method.
3. Matrix Partitioning: Divide each input matrix AA and BB into four submatrices
of equal size, each of size n/2×n/2n/2×n/2. For example:
4. Matrix Operations:
Compute seven intermediate matrices:
M1 =(A11 +A22 )×(B11 +B22 )
M2 =(A21 +A22 )×B11
M3 =A11 ×(B12 −B22 )
M4 =A22 ×(B21 −B11 )
M5 =(A11 +A12 )×B22
M6 =(A21 −A11 )×(B11 +B12 )
M7 =(A12 −A22 )×(B21 +B22 )
5. Recursive Multiplication:
Using the intermediate matrices M1,M2,…,M7M1 ,M2 ,…,M7 , compute
the resulting submatrices of the product matrix CC:
C11 =M1 +M4 −M5 +M7
C12 =M3 +M5
C21 =M2 +M4
C22 =M1 −M2 +M3 +M6
8. Return: Return the resulting matrix CC as the product of matrices AA and BB.
PESUDO CODE
function strassen_matrix_multiply(A, B)
if size(A) == 1 // Base case: A is a 1x1 matrix
return A * B
return C
function divide_matrix(M)
n = size(M)
mid = n / 2
return M[1:mid, 1:mid], M[1:mid, mid+1:n], M[mid+1:n, 1:mid], M[mid+1:n,
mid+1:n]
#include<stdio.h>
int main(){
int z[2][2];
int i, j;
int m1, m2, m3, m4 , m5, m6, m7;
int x[2][2] = {
{12, 34},
{22, 10}
};
int y[2][2] = {
{3, 4},
{2, 1}
};
printf("The first matrix is: ");
for(i = 0; i < 2; i++) {
printf("\n");
for(j = 0; j < 2; j++)
printf("%d\t", x[i][j]);
}
printf("\nThe second matrix is: ");
for(i = 0; i < 2; i++) {
printf("\n");
for(j = 0; j < 2; j++)
printf("%d\t", y[i][j]);
}
m1= (x[0][0] + x[1][1]) * (y[0][0] + y[1][1]);
m2= (x[1][0] + x[1][1]) * y[0][0];
m3= x[0][0] * (y[0][1] - y[1][1]);
m4= x[1][1] * (y[1][0] - y[0][0]);
m5= (x[0][0] + x[0][1]) * y[1][1];
m6= (x[1][0] - x[0][0]) * (y[0][0]+y[0][1]);
m7= (x[0][1] - x[1][1]) * (y[1][0]+y[1][1]);
z[0][0] = m1 + m4- m5 + m7;
z[0][1] = m3 + m5;
z[1][0] = m2 + m4;
z[1][1] = m1 - m2 + m3 + m6;
printf("\nProduct achieved using Strassen's algorithm: ");
for(i = 0; i < 2 ; i++) {
printf("\n");
for(j = 0; j < 2; j++)
printf("%d\t", z[i][j]);
}
return 0;
}
OUTPUT
COMPLEXITY ANALYSIS
Time complexity :
The time complexity of the Strassen algorithm can be analyzed using the master
theorem. Let T(n) be the time complexity of multiplying two n×n matrices using the
Strassen algorithm.
Using the master theorem, the time complexity of the Strassen algorithm is
O(n^log27), which is approximately O(n2.81). This complexity is slightly better than
the conventional matrix multiplication algorithm, which has a time complexity of
O(n3).
Space complexity :
The space complexity of the Strassen algorithm depends on the recursion depth and
the space required for intermediate matrices.
At each recursive call, the algorithm divides the matrices into submatrices, resulting
in a recursion depth of log2n.
Therefore, the space complexity of the Strassen algorithm is O(n2logn) due to the
recursion stack and the space required for intermediate matrices.
SUMMARY