0% found this document useful (0 votes)
88 views3 pages

Strassen S

The document discusses different methods for multiplying two square matrices of size n x n. It begins by describing the naive O(n3) method. A simple divide and conquer method is also O(n3) as it performs 8 recursive calls on n/2 x n/2 matrices. Strassen's method improves this by reducing the number of recursive calls to 7, yielding an time complexity of O(n2.8074) through the Master's theorem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views3 pages

Strassen S

The document discusses different methods for multiplying two square matrices of size n x n. It begins by describing the naive O(n3) method. A simple divide and conquer method is also O(n3) as it performs 8 recursive calls on n/2 x n/2 matrices. Strassen's method improves this by reducing the number of recursive calls to 7, yielding an time complexity of O(n2.8074) through the Master's theorem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Divide and Conquer | Set 5 (Strassens Matrix

Multiplication)
Given two square matrices A and B of size n x n each, find their multiplication matrix.

Naive

Method

Following is a simple way to multiply two matrices.


void multiply(int A[][N], int B[][N], int C[][N])
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
C[i][j] = 0;
for (int k = 0; k < N; k++)
{
C[i][j] += A[i][k]*B[k][j];
}
}
}
}
Run on IDE
Time Complexity of above method is O(N3).

Divide

and

Conquer

Following is simple Divide and Conquer method to multiply two square matrices.
1) Divide matrices A and B in 4 sub-matrices of size N/2 x N/2 as shown in the below diagram.
2) Calculate following values recursively. ae + bg, af + bh, ce + dg and cf + dh.

In the above method, we do 8 multiplications for matrices of size N/2 x N/2 and 4 additions. Addition of
two matrices takes O(N2) time. So the time complexity can be written as
T(N) = 8T(N/2) + O(N2)
From Master's Theorem, time complexity of above method is O(N3)
which is unfortunately same as the above naive method.

Simple Divide and Conquer also leads to O(N ), can there be a better way?
3

In the above divide and conquer method, the main component for high time complexity is 8 recursive
calls. The idea of

Strassens method is to reduce the number of recursive calls to 7. Strassens

method is similar to above simple divide and conquer method in the sense that this method also divide
matrices to sub-matrices of size N/2 x N/2 as shown in the above diagram, but in Strassens method, the
four sub-matrices of result are calculated using following formulae.

The left column represents 2x2 matrix multiplication. Nave matrix multiplication requires one multiplication for
each "1" of the left column. Each of the other columns represents a single one of the 7 multiplications in the
algorithm, and the sum of the columns gives the full matrix multiplication on the left.

Time Complexity of Strassens Method


Addition and Subtraction of two matrices takes O(N2) time. So time complexity can be written as
T(N) = 7T(N/2) + O(N2)

From Master's Theorem, time complexity of above method is


O(NLog7) which is approximately O(N2.8074)

https://en.wikipedia.org/wiki/Strassen_algorithm

You might also like