Strassian Matrix
Strassian Matrix
The traditional matrix multiplication algorithm has a time complexity of O(n3) for
multiplying two n x n matrices. However, Strassen's algorithm improves this to
O(n^log2(7)), which is approximately O(n2.81).
The algorithm achieves this improvement by recursively breaking down the matrix
multiplication into smaller subproblems and combining the results.
Complexity Analysis
Time Complexity: O(N^3), where the given matrices are square matrices of size
N*N each.
For multiplying every column with every element in the row from the given
matrices uses two loops, and adding up the values takes another loop. Therefore
the overall time complexity turns out to be O(N^3^).
Space Complexity: O(N^2), where the given matrices are square matrices of size
N*N each.
The matrix of size N*N has been used to store the result when the two matrices
are multiplied.
In the Strassen matrix multiplication algorithm, seven intermediate matrices are
defined to break down the multiplication of two matrices into smaller,
manageable operations.
A 11 (top-left) B 11(top-left)
A 12 (top-right) B12(top-right)
A21 (bottom-left) B 21(bottom-left)
A22 (bottom-right) B22(bottom-right)
Intermediate Matrices Definition
1.Matrix M1 :M1=(A11+A22)×(B11+B22)
Next, we recursively compute seven products of these submatrices, i.e., M1, M2, M3, M4, M5, M6, and M7.
Finally, we combine the results to obtain the four submatrices of the resulting
matrix C of size n x n:
C11 = M1 + M4 – M5 + M7
C12 = M3 + M5
C21 = M2 + M4
C22 = M1 – M2 + M3 + M6
Concatenate the four submatrices C11, C12, C21, and C22 to obtain the final
result matrix C.
However, due to its higher constant factors and increased overhead, Strassen's
algorithm is sometimes slower than the naive algorithm for small matrices or
practical implementations.
This pseudocode represents the Strassen algorithm, which achieves faster matrix multiplication compared
to the conventional approach by recursively breaking down the problem.
Python implementation of Strassen's algorithm for matrix multiplication.
This implementation assumes that the input matrices are square matrices of size 2n×2n for some
integer n. If the matrices are not of that size, you would typically need to pad them with zeros to the
next power of two.
import numpy as np
return C