Strassen Matrix
Strassen Matrix
Multiplication
Algorithm using
Divide and
Conquer
Divide and Conquer
► Three steps are involved:
► Divide the problem into several subproblems, perhaps of equal size
► Subproblems are solved, typically recursively
► The solutions to the subproblems are combined to get a solution to the
original problem
Real work is done in 3 different places: in partitioning; at the very tail end
of the recursion, when subproblems are so small that they are solved directly;
and in gluing together of partial solutions
Divide and Conquer (contd.)
Problem of size n
Subproblem 1 Subproblem 2
of size n/2 of size n/2
Don’t assume
always breaks up
into 2, could be > 2
subproblems
Solution to Solution to
subproblem 1 subproblem 2
Solution to the
original probelm
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];
}
}
}
} There are three for loops in this algorithm and one is nested in other. So,
the time complexity of the naive algorithm is O(n³). Hence, the algorithm
takes O(n3) time to execute.
There are three for loops in this algorithm and one is nested in
other. So, the time complexity of the naive algorithm is O(n³).
Hence, the algorithm takes O(n3) time to execute.
=1*(1-1)=0
=(1-2)*(3+1)= -4
Thank you…