ArticleslgStudy

computer science

Matrix multiplication algorithm

Matrix multiplication algorithm is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Matrix multiplication algorithm rather than just read about it. In short: Because matrix multiplication is such a central operation in many numerical algorithms, much work has been invested in making matrix multiplication algorithms efficient. Applications of matrix multiplication in computational problems are found in many fields including scientific computing and pattern recognition and in seemingly unrelated problems such as counting the paths through a graph.

Matrix multiplication algorithm — main illustration
Matrix multiplication algorithm — illustration

Key takeaways

  • Matrix multiplication algorithm belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Matrix multiplication algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Matrix multiplication algorithm from memory before moving on to harder problems.

Reference excerpt

Because matrix multiplication is such a central operation in many numerical algorithms, much work has been invested in making matrix multiplication algorithms efficient. Applications of matrix multiplication in computational problems are found in many fields including scientific computing and pattern recognition and in seemingly unrelated problems such as counting the paths through a graph. Many different algorithms have been designed for multiplying matrices on different types of hardware, including parallel and distributed systems, where the computational work is spread over multiple processors (perhaps over a network). Directly applying the mathematical definition of matrix multiplication gives an algorithm that takes time on the order of n3 field operations to multiply two n × n matrices over that field (Θ(n3) in big O notation). Better asymptotic bounds on the time required to multiply matrices have been known since the Strassen's algorithm in the 1960s, but the optimal time (that is, the computational complexity of matrix multiplication) remains unknown. As of September 2025, the best bound on the asymptotic complexity of a matrix multiplication algorithm is O(n2.371339) time, given by Alman, Duan, Williams, Xu, Xu, and Zhou. However, this algorithm is a galactic algorithm because of the large constants and cannot be realized practically.

Iterative algorithm The definition of matrix multiplication is that if C = AB for an n × m matrix A and an m × p matrix B, then C is an n × p matrix with entries

c i j = ∑ k = 1 m a i k b k j . {\displaystyle c_{ij}=\sum _{k=1}^{m}a_{ik}b_{kj}.}

From this, a simple algorithm can be constructed which loops over the indices i from 1 through n and j from 1 through p, computing the above using a nested loop:

This algorithm takes time Θ(nmp) (in asymptotic notation). A common simplification for the purpose of algorithm analysis is to assume that the inputs are all square matrices of size n × n, in which case the running time is Θ(n3), i.e., cubic in the size of the dimension.

Cache behavior

The three loops in iterative matrix multiplication can be arbitrarily swapped with each other without an effect on correctness or asymptotic running time. However, the order can have a considerable impact on practical performance due to the memory access patterns and cache use of the algorithm; which order is best also depends on whether the matrices are stored in row-major order, column-major order, or a mix of both. In particular, in the idealized case of a fully associative cache consisting of M bytes and b bytes per cache line (i.e. ⁠M/b⁠ cache lines), the above algorithm is sub-optimal for A and B stored in row-major order. When n > ⁠M/b⁠, every iteration of the inner loop (a simultaneous sweep through a row of A and a column of B) incurs a cache miss when accessing an element of B. This means that the algorithm incurs Θ(n3) cache misses in the worst case. As of 2010, the speed of memories compared to that of processors is such that the cache misses, rather than the actual calculations, dominate the running time for sizable matrices. The optimal variant of the iterative algorithm for A and B in row-major layout is a tiled version, where the matrix is implicitly divided into square tiles of size √M by √M:

In the idealized cache model, this algorithm incurs only Θ(⁠n3/b √M⁠) cache misses; the divisor b √M amounts to several orders of magnitude on modern machines, so that the actual calculations dominate the running time, rather than the cache misses.

Divide-and-conquer algorithm An alternative to the iterative algorithm is the divide-and-conquer algorithm for matrix multiplication. This relies on the block partitioning

… excerpt ends here. Continue reading the full article.

Illustrations

Matrix multiplication algorithm: Improvement of estimates of exponent ω over time for the computational complexity of matrix multiplication 
  
    
      
        O
        (
        
          n
          
            ω
          
        
        )
      
    
    {\displaystyle O(n^{\omega })}
  
.
Improvement of estimates of exponent ω over time for the computational complexity of matrix multiplication O ( n ω ) {\displaystyle O(n^{\omega })} .
Matrix multiplication algorithm: Block matrix multiplication. In the 2D algorithm, each processor is responsible for one submatrix of C. In the 3D algorithm, every pair of submatrices from A and B that is multiplied is assigned to one processor.
Block matrix multiplication. In the 2D algorithm, each processor is responsible for one submatrix of C. In the 3D algorithm, every pair of submatrices from A and B that is multiplied is assigned to one processor.
Matrix multiplication algorithm: Matrix multiplication completed in 2n-1 steps for two n×n matrices on a cross-wired  mesh.
Matrix multiplication completed in 2n-1 steps for two n×n matrices on a cross-wired mesh.

Worked examples

Example 1 — a first encounter with Matrix multiplication algorithm

Start with the simplest possible case. Write down what Matrix multiplication algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Matrix multiplication algorithm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Matrix multiplication algorithm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Matrix multiplication algorithm

In research
Matrix multiplication algorithm appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Matrix multiplication algorithm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Matrix multiplication algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Matrix multiplication algorithms, Matrix theory, Numerical linear algebra, so understanding it makes those chapters shorter.
In everyday life
Look for Matrix multiplication algorithm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Matrix multiplication algorithm” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Matrix multiplication algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Matrix multiplication algorithm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Matrix multiplication algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Matrix multiplication algorithm in simple terms?

Because matrix multiplication is such a central operation in many numerical algorithms, much work has been invested in making matrix multiplication algorithms efficient. Applications of matrix multiplication in computational problems are found in many fields including scientific computing and patte…

Why does Matrix multiplication algorithm matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Matrix multiplication algorithm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Matrix multiplication algorithm.

Tags

  • Matrix multiplication algorithms
  • Matrix theory
  • Numerical linear algebra

Keep exploring