0% found this document useful (0 votes)
32 views

Strassen's Algorithm For MATRIX MULTIPLICATION

Divide and conquer strategy

Uploaded by

Shivangi Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Strassen's Algorithm For MATRIX MULTIPLICATION

Divide and conquer strategy

Uploaded by

Shivangi Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

DESIGN AND GROUP 7 : 2.3 AND 4.

ANALYSIS OF Shivangi Gupta - 22570005


ALGORITHMS Rashmi - 22570042
Kumari Deepti - 22570075
Submitted to :
Anshula Ma'am
DIVIDE AND CONQUER
This technique can be divided into the following three
parts:

Divide: This involves dividing the problem into smaller


sub-problems.
Conquer: Solve sub-problems by calling recursively until
solved.
Combine: Combine the sub-problems to get the final
solution of the whole problem.

1 2 3
Divide Conquer Combine
DIVIDE-AND-CONQUER APPROACH:
To find the maximum and minimum element from a given
array is an application for divide and conquer. In this Some standard algorithms that
problem, we will find the maximum and minimum
elements in a given array. In this problem, we are using a
follow Divide and Conquer
divide and conquer approach(DAC) which has three steps algorithm are:-
divide, conquer and combine.

Quicksort

Merge sort

Closest Pair of Points

Strassen’s Algorithm
DIVIDE AND RECURRENCE
CONQUER RELATION FOR
ALGORITHM : DAC ALGORITHM :

DAC(a, I, j)
{
If(small(a, I, j))
return(Solution(a, I, j)) T(n) = O(1) if n is small;
else f1(n) + 2T(n/2) + f2(n)
mid = divide(a, I, j)
b= DAC(a, I, mid)
c = DAC(a, mid+1, j)
d= combine(b, c)// f2(n)
return(d)
}
MERGE SORT STEPS
1) Divide: Divide the list or array
recursively into two halves until it
can no more be divided.

2) Conquer: Each subarray is sorted


individually using the merge sort
algorithm.

3) Merge: The sorted subarrays are MERGE SORT IS A SORTING ALGORITHM THAT FOLLOWS
merged back together in sorted THE DIVIDE-AND-CONQUER APPROACH. IT WORKS BY
order. The process continues until RECURSIVELY DIVIDING THE INPUT ARRAY INTO
all elements from both subarrays SMALLER SUBARRAYS AND SORTING THOSE
have been merged. SUBARRAYS THEN MERGING THEM BACK TOGETHER TO
OBTAIN THE SORTED ARRAY.

Merge Sort
Merge sort Algorithm:

MERGE(A, p, q ,r)
1 n1= q -p + 1
2 n2=r- q
3 let L(1..n1 +1) and R(1..n2 +1) be new
arrays
4 for i=1 to n1
5 L(i)=A(p+i-1)
6 for j =1 to n2
7 R(j)=A(q+j)
8 L(n1 +1) = ♾️
9 R(n2+1) = ♾️
10 i=1
11 j=1
12 for k =p to r
13 if L(i)<=R(j)
14 A(k)=L(i)
15 i=i+1
16 else A(k)=R(j)
17 j=j+1
COMPLEXITY
ANALYSIS OF Average Case Worst Case
Best Case
MERGE SORT:
Time Complexity;
O(n log n)
O(n log n)
O(n log n)
When the array is
When the array is
already sorted or When the array is
sorted in reverse
nearly sorted. randomly ordered.
order.
EXAMPLE:

DIVIDE CONQUER COMBINE

38 27 43 10
Merge [38] and [27] to get
DIVIDE [38] is already sorted. [27, 38].
[27] is already sorted. Merge [43] and [10] to get
[10,43].
38 27 43 10 [43] is already sorted.
Merge [27, 38] and [10,43] .
[10] is already sorted.
DIVIDE
DIVIDE
10 27 38 43
4.2 STRASSEN’S ALGORITHM FOR MATRIX
MULTIPLICATION

WHAT IS STRASSEN’S
ALGORITHM?

Many mathematicians presumed that it


was not possible to multiply matrices in
o(n^3) time until 1969, when V. Strassen
published a remarkable recursive
algorithm for multiplying n * n matrices.

Strassen’s algorithm runs in O(n ^lg 7)


time. Since log 7 = 2.8073549…,
Strassen’s algorithm runs in O(n^2.81)
time.
STEPS OF STRANSSEN’S
ALGORITHM. Algorithm:

Naive Method: Matrix-Multiplication(X, Y, Z)


The usual matrix multiplication for i = 1 to p do
method multiplies each row for j = 1 to r do
with each column to achieve
Z[i, j] := 0
the product matrix.
The time complexity of this for k = 1 to q do
approach is O(n^3) since it Z[i, j] := Z[i, j] + X[i, k] ×
involves two nested loops for Y[k, j]
multiplication.
Pseudocode for Naive
multiplication:
STRASSEN’S MATRIX
MULTIPLICATION
ALGORITHM:

Strassen’s method I K
reduces the time
Z= J L
complexity from O(n^3) to
O(n^log7).
It can be performed only A C
on square matrices where X= B D
n is a power of 2.
Divide matrices X, Y, and Z
into four (n/2) × (n/2) E G
Y=
submatrices as follows: F H
QUESTION- 4.2-1
USE STRASSEN’S ALGORITHM TO COMPUTE THE MATRIX PRODUCT:

M1 = (A + C) × (E + F)
M1 = 6
M2 = (B + D) × (G + H)
M2 = 8
M3 = (A - D) × (E + H)
M3 = 72
M4 = A × (F - H)
M4 = −10
M5 = (C + D) × E
M5 = 48 So, we get the final result:
M6 = (A + B) × H
M6 = −12
M7 = D × (G - E)
M7 = −84

Then:
I = C11 = 48 − 10 − 8 − 12 = 18
I = C11 = M2 + M3 - M6 - M7
J = C12 = 6 + 8 = 14
J = C12 = M4 + M6
K = C21 = 72 − 10 = 62
K = C21 = M5 + M7
L = C22 = 48 + 6 − 72 + 84 = 66
L = C22 = M1 - M3 - M4 - M5
Thank you
very much!
Group 7

You might also like