AlgoScope

Matrix Chain Multiplication

Algorithmadvanced2D Dynamic Programming

dp[i][j] is the cheapest way to multiply Mi..Mj, trying every position for the last multiplication.

Decision · step 2 of 8Interval DP: Four matrices
012301230✓60000✓0✓0✓

dp[0][1], length 2: split at 0: 0 + 0 + 6000 = 6000. Best is 6000, splitting at 0: multiply (M0..M0), a 10 x 20, by (M1..M1), a 20 x 30, for 10 x 20 x 30 = 6000.

Open in the player →or start at step 2

What you will see

The table fills by diagonal (interval length); each cell tries every split.

How interval dp works →

Cost

BestO(n^3)
AverageO(n^3)
WorstO(n^3)
SpaceO(n^2)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.

Screen readers: Table cells announce their state and value; each step announces which cells were read and the value written.

Reduced motion: Dependency arrows appear statically and the cell value crossfades.

Before this

Taught by the same lesson

Interval DP covers these too, in the same run.