AlgoPlus//dynamic programming / matrix-chain
Read the theory

Matrix Chain Multiplication

Find the cheapest way to parenthesize a chain of matrix products.

Phase
Fill table
Cell
Min cost
Dimensions (space or comma separated, ≥3 numbers)
Legend
Current cell
Left half
Right half
AI Tutor Workspace
In a nutshell
Multiplying a chain of matrices gives the same result no matter how you bracket it, but some bracketings need far fewer multiplications. This fills a table with the cheapest cost for every stretch of the chain, trying each split point, so the best way to parenthesize the whole product falls out at the end.
Ready
Press play to begin the cinematic walkthrough.
The product is the same however you bracket it, but the work isn't. Solve every sub-chain once and try each split point — the cheapest place to cut is what you remember.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Matrix Chain Multiplication.