Reputation: 97
I was doing an Algorithm's Course. While, covering divide and conquer, I came across Strassen's Algorithm.
So, the issue is how do we multiply matrices with odd degrees, or even degrees which are not powers of 2?
Also, how do we apply Strassen's Algorithm for matrices of different dimensions (like multiplying a 2X3 matrix with 3X1 matrix)?
Upvotes: 1
Views: 978
Reputation: 2129
Say the matrices are of degree n
. A simple thing you can do if you want to multiply A
and B
is to pad out A
and B
with zeros (say A_pad
, B_pad
so that they are of dim (k,k)
where k
is smallest power of two that upper bounds n
. Since k
is at most twice the original dimensions,
k^log_2(7)<=3 * N^log_2(7)
So the algorithm is still O(N^log_2(7))
.
This approach doesn't quite work with matrices of different dimensions in a situation where one of the matrices is "thin" (say the length of A dominates the height of A). In this case you would need to slice the matrices to get matrices that are more square-like, as mentioned the comment by @neil-edelman. The way you would determine thinness could be to see if BND>dim(A)[1]/dim(A)[0]>bnd
where bnd
and BND
are some constant parameters chosen before-hand, close to 1.
Upvotes: 1