0% found this document useful (0 votes)
494 views12 pages

Strassen's Matrix Multiplication

Uploaded by

kishwaryarani
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)
494 views12 pages

Strassen's Matrix Multiplication

Uploaded by

kishwaryarani
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

STRASSEN’S MATRIX MULTIPLICATION

Definition:
Strassen’s Matrix Multiplication is an efficient algorithm for
multiplying two square matrices. It was developed by Volker
Strassen in 1969. The algorithm reduces the time complexity of
matrix multiplication from O(n^3) to O(n^2.81).

Key Concepts:

1. Divide and Conquer: Break down the problem into smaller


sub-problems.
2. Recursion: Apply the same algorithm to sub-problems.
3. Matrix Splitting: Divide matrices into quarters.

Strassen’s Algorithm:

Input:Two n x n matrices A and B.

Output: Product matrix C = A x B.

Step-by-Step Explanation:

1. Base Case: If n = 1, return A x B (scalar multiplication).


2. Split Matrices: Divide A, B, and C into quarters:

A = [A11, A12; A21, A22]


B = [B11, B12; B21, B22]
C = [C11, C12; C21, C22]

3. Compute Intermediate Matrices:(7 multiplications)

M1 = (A11 + A22) x (B11 + B22)


M2 = (A21 + A22) x B11
M3 = A11 x (B12 – B22)
M4 = A22 x (B21 – B11)
M5 = (A11 + A12) x B22
M6 = (A21 – A11) x (B11 + B12)
M7 = (A12 – A22) x (B21 + B22)

4. Compute Product Matrix: (8 additions/subtractions)

C11 = M1 + M4 – M5 + M7
C12 = M3 + M5
C21 = M2 + M4
C22 = M1 + M3 – M2 + M6

5. Combine Quarters: Assemble C from C11, C12, C21, C22.

Example:

Suppose we want to multiply two 2x2 matrices:


A = [1, 2; 3, 4]
B = [5, 6; 7, 8]

Step 1: Split matrices

A11 = 1, A12 = 2, A21 = 3, A22 = 4


B11 = 5, B12 = 6, B21 = 7, B22 = 8

Step 2-3: Compute intermediate matrices

M1 = (1+4) x (5+8) = 5 x 13 = 65
M2 = (3+4) x 5 = 7 x 5 = 35
M3 = 1 x (6-8) = 1 x -2 = -2
M4 = 4 x (7-5) = 4 x 2 = 8
M5 = (1+2) x 8 = 3 x 8 = 24
M6 = (3-1) x (5+6) = 2 x 11 = 22
M7 = (2-4) x (7+8) = -2 x 15 = -30

Step 4: Compute product matrix

C11 = 65 + 8 – 24 + (-30) = 19
C12 = -2 + 24 = 22
C21 = 35 + 8 = 43
C22 = 65 + (-2) – 35 + 22 = 50

Step 5: Combine quarters

C = [19, 22; 43, 50]


Number of Multiplications:

M(n) = 7M(n/2) + 0
Where M(n) is the number of multiplications for an n × n matrix.

Number of Additions/Subtractions:

A(n) = 18A(n/2) + 4n^2


Where A(n) is the number of additions/subtractions for an n × n
matrix.
Total Operations:

T(n) = M(n) + A(n)


= 7M(n/2) + 18A(n/2) + 4n^2

Solving the Recurrence Relations:


M(n) = 7M(n/2)
= 7^k M(n/2^k)
= 7^k M(1)
= 7^k (since M(1) = 1)
= O(n^log2(7))
= O(n^2.81)

A(n) = 18A(n/2) + 4n^2


= O(n^2.81) (after solving the recurrence relation)

Number of Operations for Strassen’s Algorithm:

Multiplications ➔ 7n^2.81
Additions/Subtractions ➔18n^2.81 + 4n^2
Total Operations ➔ 25n^2.81 + 4n^2
Comparison with Standard Matrix Multiplication:

Standard
Multiplication ➔ n^3 |
Additions/Subtractions ➔ n^2(n-1)
Strassen
Multiplications➔ 7n^2.81 |
Additions/Subtractions➔ 18n^2.81 + 4n^2 |

NOTE :
Strassen’s algorithm reduces the number of multiplications but
increases the number of additions/subtractions.
- n is the number of rows (or columns) in the matrix.
- M(n) represents the number of multiplications.
- A(n) represents the number of additions/subtractions.
- T(n) represents the total number of operations.
- O(n^2.81) indicates the time complexity grows approximately as
n^2.81.

Formulas:

Number of Multiplications:
M(n) = 7M(n/2) + 0
Number of Additions/Subtractions:
A(n) = 18A(n/2) + 4n^2

Total Operations:
T(n) = M(n) + A(n)

Example 1: 2x2 Matrix


Suppose we want to multiply two 2x2 matrices:

A = [a11, a12; a21, a22]


B = [b11, b12; b21, b22]

Multiplications:

M(2) = 7M(1) = 7 (since M(1) = 1)

Additions/Subtractions:
A(2) = 18A(1) + 4(2)^2 = 18 + 16 = 34

Total Operations:

T(2) = M(2) + A(2) = 7 + 34 = 41


Example 2: 4x4 Matrix

Suppose we want to multiply two 4x4 matrices:

A = [a11, a12, a13, a14; a21, a22, a23, a24; a31, a32, a33, a34;
a41, a42, a43, a44]
B = [b11, b12, b13, b14; b21, b22, b23, b24; b31, b32, b33, b34;
b41, b42, b43, b44]

Multiplications:

M(4) = 7M(2) = 7(7) = 49

Additions/Subtractions:

A(4) = 18A(2) + 4(4)^2 = 18(34) + 64 = 652

Total Operations:

T(4) = M(4) + A(4) = 49 + 652 = 701


Example 3: 8x8 Matrix

Suppose we want to multiply two 8x8 matrices:

A = [a11, …, a18; …; a81, …, a88]


B = [b11, …, b18; …; b81, …, b88]

Multiplications:

M(8) = 7M(4) = 7(49) = 343

Additions/Subtractions:

A(8) = 18A(4) + 4(8)^2 = 18(652) + 256 = 12,032

Total Operations:

T(8) = M(8) + A(8) = 343 + 12,032 = 12,375

Time Complexity: O(n^2.81), which is better than the standard


matrix multiplication algorithm’s O(n^3) for large matrices.
Space Complexity: O(n^2) for the recursive calls and temporary
matrices.

Advantages:

1. Faster Computation: Strassen’s algorithm reduces the time


complexity of matrix multiplication from O(n^3) to
O(n^2.81).
2.
3. Efficient for Large Matrices: Suitable for multiplying large
matrices, where standard algorithms are impractical.

4. Parallelization: Can be parallelized, making it suitable for


distributed computing.

5. Reduced Number of Multiplications: Requires fewer


multiplications compared to standard algorithms.

6. Improved Performance: Provides better performance for


certain matrix sizes.

Disadvantages:

1. Increased Number of Additions: Requires more additions


compared to standard algorithms.
2. Higher Constant Factors: Has higher constant factors,
making it slower for small matrices.
3. Complexity: More complex implementation compared to
standard algorithms.

4. Memory Requirements: Requires more memory for


temporary matrices.

5. Limited Applicability: Not suitable for all matrix sizes or


types (e.g., sparse matrices).

When to Use Strassen’s Algorithm:

1. Large matrices (n > 100).


2. Matrix multiplication is a bottleneck.
3. Parallel computing environment.
4. High-performance computing applications.

When Not to Use Strassen’s Algorithm:

1. Small matrices (n < 10).


2. Sparse matrices.
3. Memory-constrained environments.
4. Simple matrix multiplication requirements.

Real-World Applications:

1. Computer graphics.
2. Machine learning.
3. Scientific simulations.
4. Data analysis.
5. Cryptography.

Alternative Algorithms:

1. Coppersmith-Winograd algorithm (O(n^2.376)).


2. Standard matrix multiplication (O(n^3)).
3. Sparse matrix multiplication algorithms

You might also like