Divide-and-Conquer for Matrix Multiplication: From Naive to Strassen's Algorithm

Multiplying two matrices is a fundamental operation in computer science, and the naive approach is far from optimal. This comprehensive guide explains the standard cubic-time matrix multiplication algorithm, shows how a straightforward divide-and-conquer approach fails to improve on it, and walks through Strassen's remarkable algorithm that achieves a genuinely faster asymptotic running time.

Matrix MultiplicationStrassen's AlgorithmDivide-and-Conquer

~5 min read · Updated Sep 7, 2026

The Matrix Multiplication Problem

Given two n × n matrices A and B, the goal is to compute their product C = A × B, where each entry is defined as:

C[i][j] = Σ (for k = 1 to n) A[i][k] × B[k][j]

This operation appears throughout computer science and applied mathematics, from computer graphics transformations to solving systems of linear equations to the neural network computations underlying modern machine learning.

The Naive Algorithm

The straightforward approach directly implements the mathematical definition using three nested loops.

SQUARE-MATRIX-MULTIPLY(A, B, n):
  let C be a new n × n matrix
  for i = 1 to n:
      for j = 1 to n:
          C[i][j] = 0
          for k = 1 to n:
              C[i][j] = C[i][j] + A[i][k] · B[k][j]
  return C

Each entry of the output matrix requires n multiplications and additions, and there are entries to compute, giving a total running time of Θ(n³). For decades, this cubic running time was assumed to be essentially unavoidable for matrix multiplication.

A First Attempt: Naive Divide-and-Conquer

Applying the divide-and-conquer paradigm, an n × n matrix can be partitioned into four n/2 × n/2 submatrices, and matrix multiplication can be expressed recursively in terms of these submatrices.

Partition A and B into quadrants:
A = [A11  A12]      B = [B11  B12]
    [A21  A22]          [B21  B22]

The product C = A × B is then:
C11 = A11·B11 + A12·B21
C12 = A11·B12 + A12·B22
C21 = A21·B11 + A22·B21
C22 = A21·B12 + A22·B22

This requires 8 recursive multiplications of n/2 × n/2 submatrices, plus 4 additions of n/2 × n/2 matrices, each taking Θ(n²) time. The resulting recurrence is:

T(n) = 8T(n/2) + Θ(n²)

Solving this recurrence, using the master method covered in the next article of this series, gives T(n) = Θ(n³) — exactly the same asymptotic running time as the naive triple-loop algorithm. Simply reformulating the problem recursively provided no improvement.

Strassen's Breakthrough Insight

In 1969, Volker Strassen discovered a way to compute the product of two 2×2 matrices using only 7 multiplications instead of 8, at the cost of additional matrix additions and subtractions. Since multiplications are the more expensive operation asymptotically when applied recursively, this small reduction has an outsized effect on the overall running time.

Strassen's algorithm first computes 7 intermediate products using specific combinations of submatrix sums and differences:

P1 = A11 · (B12 - B22)
P2 = (A11 + A12) · B22
P3 = (A21 + A22) · B11
P4 = A22 · (B21 - B11)
P5 = (A11 + A22) · (B11 + B22)
P6 = (A12 - A22) · (B21 + B22)
P7 = (A11 - A21) · (B11 + B12)

The four output quadrants are then reconstructed purely from these 7 products, using only addition and subtraction:

C11 = P5 + P4 - P2 + P6
C12 = P1 + P2
C21 = P3 + P4
C22 = P5 + P1 - P3 - P7

Verifying these formulas algebraically confirms they produce exactly the same result as the standard matrix multiplication formulas, but using one fewer multiplication at each level of recursion.

Analyzing Strassen's Running Time

Since each level of recursion now requires only 7 recursive multiplications of half-sized submatrices, plus a constant number of Θ(n²) additions and subtractions, the recurrence becomes:

T(n) = 7T(n/2) + Θ(n²)

Solving this recurrence using the master method yields T(n) = Θ(n^log₂7) ≈ Θ(n^2.807), a genuine asymptotic improvement over the naive Θ(n³) algorithm. While the improvement from exponent 3 to approximately 2.807 might seem modest, it becomes significant for very large matrices, and it proved something profoundly important: cubic time is not fundamentally required for matrix multiplication, opening the door to decades of further research into even faster algorithms.

Practical Considerations

Despite its better asymptotic complexity, Strassen's algorithm is rarely used in practice for typical matrix sizes, for several practical reasons. The algorithm has a larger constant factor hidden inside the asymptotic notation, meaning it only outperforms the naive algorithm once matrices become quite large. It is also less numerically stable than the naive approach, since the additional additions and subtractions can amplify floating-point rounding errors. Real-world numerical libraries typically use a hybrid approach: applying Strassen's algorithm recursively down to some threshold size, then switching to the naive algorithm for the base case, to get the asymptotic benefit while minimizing overhead and numerical instability.

Why This Result Matters Beyond Matrix Multiplication

Strassen's algorithm is historically significant well beyond its immediate practical application. It was one of the first results to demonstrate that a problem's naive algorithm, however intuitive, is not necessarily asymptotically optimal, inspiring an entire subfield of research into fast matrix multiplication that continues to this day, with the current best-known algorithms achieving exponents even lower than Strassen's original bound, though with constant factors so large they remain purely of theoretical interest.

Written & researched by Dr. Shahin Siami

Related Articles

Quicksort: A Complete Guide to Description, Performance, and Randomization

Quicksort is one of the most widely used sorting algorithms in practice, prized for its excellent average-case performance and in-place operation, despite having a poor theoretical worst case. This comprehensive guide covers the partition-based algorithm in detail, analyzes both its worst-case and expected running time, and explains how randomization transforms it into a reliably efficient algorithm regardless of input order.

Continue

Heapsort and Priority Queues: A Complete Guide to the Binary Heap

The binary heap is one of the most elegant data structures in computer science, enabling both an efficient in-place sorting algorithm and the priority queue abstraction used throughout algorithm design. This comprehensive guide covers heap properties and array representation, the core heapify operation, building a heap from an unordered array, the complete heapsort algorithm, and priority queue operations built on top of heaps.

Continue

Probabilistic Analysis and Randomized Algorithms: The Hiring Problem Explained

Some algorithms make random choices during execution, and analyzing their expected behavior requires a different toolkit than worst-case analysis alone. This comprehensive guide introduces probabilistic analysis through the classic hiring problem, explains indicator random variables as a powerful analytical tool, and shows how randomization can improve an algorithm's expected performance.

Continue

Solving Recurrences: Substitution, Recursion Trees, and the Master Method

Every divide-and-conquer algorithm's running time is captured by a recurrence relation, and solving that recurrence is essential to understanding the algorithm's efficiency. This comprehensive guide covers the three standard techniques for solving recurrences: the substitution method for proving a guessed bound, the recursion-tree method for generating a guess, and the master method as a fast shortcut for a common class of recurrences.

Continue

Asymptotic Notation: A Complete Guide to O, Ω, and Θ

Comparing algorithms fairly requires a mathematical language that ignores constant factors and focuses on growth rate as input size becomes large. This comprehensive guide covers the formal definitions of Big-O, Big-Omega, and Big-Theta notation, explains how to prove asymptotic bounds directly from their definitions, and surveys the standard functions and growth rates every algorithm analysis relies on.

Continue

What Algorithms Are and How to Analyze Them: A Complete Starting Guide

Before diving into specific algorithms, it is essential to understand what an algorithm actually is, why studying algorithms matters even with fast modern hardware, and how to rigorously analyze an algorithm's efficiency. This comprehensive guide covers the formal definition of an algorithm, walks through insertion sort as a first complete example, and introduces the core techniques for measuring and comparing running time.

Continue