Algorithms · Visualized

Strassen's Matrix Multiplication

Divide & Conquer

Break a problem into independent subproblems, solve each, and combine the answers.

Strassen multiplies two n×n matrices faster than O(n³) by splitting each into quadrants and combining just 7 (not 8) recursive multiplications through clever additions and subtractions — trading extra additions for a saved multiplication at every level. Time: O(n^2.807) average, O(n^2.807) versus O(n³) naive worst; space: O(n²) — intermediate submatrices.

Big-O: Classic D&C recursions: Merge Sort, Quick Sort, Maximum Subarray, Fast Power.

Strassen's Matrix Multiplication

Divide & Conquer

Strassen multiplies two n×n matrices faster than O(n³) by splitting each into quadrants and combining just 7 (not 8) recursive multiplications through clever additions and subtractions — trading extra additions for a saved multiplication at every level.

How Strassen's Matrix Multiplication Works

  1. Split each matrix into four (n/2)×(n/2) quadrants: A11, A12, A21, A22 and B11, B12, B21, B22.
  2. Compute 7 products M1–M7 using sums/differences of the quadrants (e.g. M1 = (A11+A22)·(B11+B22)).
  3. Combine the 7 products with additions and subtractions to form the four quadrants of the result C.
  4. Recurse until a base-case size is reached, then multiply directly.

Strassen's Matrix Multiplication Worked Example

Input: {A: [[1, 2], [3, 4]], B: [[5, 6], [7, 8]]}

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=M1+M4−M5+M7=19, C12=M3+M5=22, C21=M2+M4=43, C22=M1−M2+M3+M6=50. So A×B = [[19,22],[43,50]] using 7 multiplications instead of 8.

Strassen's Matrix MultiplicationO(n^2.807)
Multiply 2×2 blocks with 7 products instead of 8 — O(n^2.807).
1
2
5
6
3
4
7
8
A[[1,2],[3,4]]
B[[5,6],[7,8]]
Step 1 / 11
Default Current / Compare Swap / Write Settled Active / Path Pivot / Reject Locked (hollow) Target
Strassen: multiply A × B (2×2) with 7 recursive products instead of 8. Quadrants: A11,A12,A21,A22 and B11,B12,B21,B22.
Python · Divide & Conquer in Code
def mul(a, b):
    m1 = (a[0][0] + a[1][1]) * (b[0][0] + b[1][1])
    m2 = (a[1][0] + a[1][1]) * b[0][0]
    m3 = a[0][0] * (b[0][1] - b[1][1])
    m4 = a[1][1] * (b[1][0] - b[0][0])
    m5 = (a[0][0] + a[0][1]) * b[1][1]
    m6 = (a[1][0] - a[0][0]) * (b[0][0] + b[0][1])
    m7 = (a[0][1] - a[1][1]) * (b[1][0] + b[1][1])
    return [
        [m1 + m4 - m5 + m7, m3 + m5],
        [m2 + m4, m1 - m2 + m3 + m6],
    ]

Behind the Scenes Execution

Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.

Strassen's Matrix Multiplication Time & Space Complexity

BestO(n^2.807)
AverageO(n^2.807)
WorstO(n^2.807) versus O(n³) naive
SpaceO(n²) — intermediate submatrices

When to Use Strassen's Matrix Multiplication

  • Large-scale numerical and scientific computing.
  • Graphics and physics engines doing bulk matrix math.
  • The theoretical basis for further sub-cubic matrix multiplication research.

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Keep the momentum going

Step through a related structure, pattern or course — the ideas reinforce each other and stick faster.