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).

x1 = (a11 + a22)(b11 + b22)
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)
Key Insight: While this seems like more work for 2×2 matrices (25 operations vs 12), when applied recursively to large matrices, saving one multiplication at each level compounds into significant savings: O(nlog27) ≈ O(n2.81) vs O(n3).

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

32 × 32
Hybrid threshold: T = 32

Standard

32,768
multiplications
Additions: 31,744 Total: 64,512

Pure Strassen

16,807
multiplications
Additions: 58,482 Total: 75,289

Hybrid Strassen

--
multiplications
Additions: -- Total: --

Total Operations Comparison

Standard
64,512
baseline
Pure Strassen
75,289
1.17x slower
Hybrid
--
--

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

--
milliseconds
Avg per trial: --

Pure Strassen

--
milliseconds
Avg per trial: --

Hybrid Strassen

--
milliseconds
Avg per trial: --

Execution Time Comparison

Standard
--
baseline
Pure Strassen
--
--
Hybrid
--
--
Note: JavaScript is slower than C, so times will be higher than the paper's benchmarks. However, the relative performance differences should be similar. Hybrid Strassen should consistently beat both standard and pure Strassen for larger matrices.

Key Findings from My Research

Actual Benchmarks (from my C implementation)

n Standard (s) Pure Strassen (s) Hybrid Strassen (s) Hybrid Speedup
320.0000690.0004650.0000501.38×
640.0005560.0032010.0003771.47×
1280.0042670.0227080.0024131.77×
2560.0347720.1600490.0183261.87×
5120.2774401.1222730.1352342.06×
10002.2038587.8394320.9220532.40×

Benchmarks run on my machine with 100 trials per size. See the paper for full methodology.