What is matrix chain multiplication?

Matrix chain multiplication is the process of multiplying multiple matrices with only a few arithmetic operations.

Remember, matrix multiplication is an associative property.

The trick is to place parenthesis in such an order that the result is computed with only a few arithmetic operations.

Example

Consider three matrices, where A is 2x3, B is 3x5, and C is 5x10.

svg viewer

Since the first case involves fewer arithmetic operations, it is a better approach.

Approach

A simple approach to this is to place parenthesis at all the possible positions and calculate the operational cost. Finding the minimum operational cost for one possible position is the optimal way of solving a chain of matrices. If there are four (n) matrices, then there are three (n-1) ways to place the parenthesis.

  • A(BCD)
  • (AB)(CD)
  • (ABC)D
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved