Strassen's Algorithm
This project explores Strassen's Algorithm, a divide-and-conquer method for matrix multiplication that achieves O(n2.81) time complexity, improving upon the standard O(n3) algorithm.
I wrote an in-depth paper on this topic for MATH 299 at Haverford College, which includes proofs of correctness, time complexity analysis, and practical benchmarks comparing pure Strassen, hybrid Strassen, and standard multiplication.
How It Works
Standard matrix multiplication computes each entry of the result matrix using dot products, requiring 8 multiplications for 2×2 matrices. Strassen discovered that you can compute the same result with only 7 multiplications (at the cost of more additions).
x2 = (a21 + a22)b11
x3 = a11(b12 - b22)
x4 = a22(-b11 + b21)
x5 = (a11 + a12)b22
x6 = (-a11 + a21)(b11 + b12)
x7 = (a12 - a22)(b21 + b22)
Interactive Performance Demo
See how operation counts scale with matrix size and why hybrid Strassen outperforms both pure methods:
Performance Comparison
Adjust matrix size to see how each algorithm scales
Standard
Pure Strassen
Hybrid Strassen
Why Hybrid Wins
At this size, hybrid Strassen uses Strassen's recursion at the top levels to reduce multiplications, then switches to standard multiplication at the base case to avoid the overhead of extra additions. This gives the best of both worlds.
Live Timing Benchmark
Run the algorithms in your browser and measure actual execution time
Standard
Pure Strassen
Hybrid Strassen
Key Findings from My Research
- Pure Strassen is slower in practice for small matrices due to recursion overhead and extra additions.
- Hybrid Strassen (switching to standard multiplication below a threshold) achieves 1.4–2.4× speedup over standard multiplication for n ≥ 32.
- The optimal threshold on my machine was T = 16–32.
- Strassen's algorithm should be viewed as a tool for reducing the cost of large matrix multiplications, not a replacement for standard multiplication.
Actual Benchmarks (from my C implementation)
| n | Standard (s) | Pure Strassen (s) | Hybrid Strassen (s) | Hybrid Speedup |
|---|---|---|---|---|
| 32 | 0.000069 | 0.000465 | 0.000050 | 1.38× |
| 64 | 0.000556 | 0.003201 | 0.000377 | 1.47× |
| 128 | 0.004267 | 0.022708 | 0.002413 | 1.77× |
| 256 | 0.034772 | 0.160049 | 0.018326 | 1.87× |
| 512 | 0.277440 | 1.122273 | 0.135234 | 2.06× |
| 1000 | 2.203858 | 7.839432 | 0.922053 | 2.40× |
Benchmarks run on my machine with 100 trials per size. See the paper for full methodology.