Strassen showed in 1969 that two matrices can be multiplied with fewer than n³ multiplications.
The Divide and Conquer Idea
Split each n × n matrix into four n/2 × n/2 blocks. The ordinary block method needs 8 multiplications of n/2 × n/2 matrices plus additions, so T(n) = 8T(n/2) + n², which by the Master theorem is Θ(n³): no gain. Strassen noticed that 7 multiplications are enough, at the cost of more additions and subtractions. Since adding matrices costs only Θ(n²), one saved multiplication of a large matrix is a big gain.
The Seven Products
For A = [[a11, a12], [a21, a22]] and B = [[b11, b12], [b21, b22]], compute:
M1 = (a11 + a22)(b11 + b22); M2 = (a21 + a22)·b11; M3 = a11·(b12 − b22); M4 = a22·(b21 − b11); M5 = (a11 + a12)·b22; M6 = (a21 − a11)(b11 + b12); M7 = (a12 − a22)(b21 + b22). Then
C11 = M1 + M4 − M5 + M7; C12 = M3 + M5; C21 = M2 + M4; C22 = M1 − M2 + M3 + M6. The method is applied recursively on the blocks, so the entries a11, ... above are themselves matrices.
Analysis
The recurrence is T(n) = 7T(n/2) + cn². In the Master theorem a = 7, b = 2, c₀ = log₂ 7 ≈ 2.807 and f(n) = n² is polynomially smaller, so Case 1 gives T(n) = Θ(n^2.81). For n = 1024 the classical method does about 1.07 billion multiplications while Strassen does about 282 million at the multiplication level, though the extra additions matter. In practice Strassen pays off only for large matrices (hundreds of rows), needs extra memory, and is slightly less numerically stable, so libraries use it only above a cut-off size and the classical method below.
Definition: Strassen's algorithm. A divide and conquer method that multiplies two n × n matrices using 7 recursive multiplications of n/2 × n/2 matrices instead of 8, giving Θ(n^log₂7) ≈ Θ(n^2.81) time.
Table 2.4: Classical versus Strassen
| Basis | Classical block method | Strassen |
|---|---|---|
| Block multiplications | 8 | 7 |
| Recurrence | 8T(n/2) + n² | 7T(n/2) + n² |
| Complexity | Θ(n³) | Θ(n^2.81) |
| Extra additions | Few | 18 per step |
| Practical use | Small matrices | Very large matrices |
Example 2.4: Strassen on 2 × 2
Problem: Multiply A = [[1, 2], [3, 4]] by B = [[5, 6], [7, 8]] using Strassen's seven products.
Solution:
- M1 = (1 + 4)(5 + 8) = 65; M2 = (3 + 4)·5 = 35; M3 = 1·(6 − 8) = −2; M4 = 4·(7 − 5) = 8.
- M5 = (1 + 2)·8 = 24; M6 = (3 − 1)(5 + 6) = 22; M7 = (2 − 4)(7 + 8) = −30.
- C11 = 65 + 8 − 24 − 30 = 19; C12 = −2 + 24 = 22.
- C21 = 35 + 8 = 43; C22 = 65 − 35 − 2 + 22 = 50.
Result: C = [[19, 22], [43, 50]], the same as the classical product, with 7 multiplications instead of 8.
def strassen2(A, B):
(a, b), (c, d) = A
(e, f), (g, h) = B
m1, m2, m3 = (a+d)*(e+h), (c+d)*e, a*(f-h)
m4, m5 = d*(g-e), (a+b)*h
m6, m7 = (c-a)*(e+f), (b-d)*(g+h)
return [[m1+m4-m5+m7, m3+m5], [m2+m4, m1-m2+m3+m6]]
print(strassen2([[1, 2], [3, 4]], [[5, 6], [7, 8]]))
import math
print("exponent log2(7) =", round(math.log2(7), 3))
n = 1024
print("classical:", n**3, " strassen:", round(n**math.log2(7)))
Output
[[19, 22], [43, 50]]
exponent log2(7) = 2.807
classical: 1073741824 strassen: 282475249
Common mistakes
- Quoting Strassen as Θ(n²); it is about n^2.81.
- Forgetting the extra additions, which make it slower on small matrices.
- Mixing up the signs in the C11 and C22 formulas.
- Applying it directly when n is not a power of 2 without padding with zeros.
Key takeaways
- Strassen uses 7 multiplications instead of 8 on n/2 blocks.
- T(n) = 7T(n/2) + cn² solves to Θ(n^log₂7) = Θ(n^2.81).
- It is worthwhile only for large matrices.
- C11 = M1 + M4 − M5 + M7; C12 = M3 + M5; C21 = M2 + M4; C22 = M1 − M2 + M3 + M6.
Practice questions
- How many multiplications does Strassen use per step?
- What is Strassen's time complexity?
- Why is the classical block method still Θ(n³)?
Answers to the practice questions
- Seven, instead of eight.
- Θ(n^log₂7), about Θ(n^2.81).
- Eight half-size products give T(n) = 8T(n/2) + n², which is Θ(n³).
Sources
- Official BCA syllabus Design and Analysis of Algorithms, course code 26BCA404DS03, Unit II
