Algorithms · Matrix Chain Multiplication Worked Table, Catalan Counting and Optimal BST
The problem, from zero
This chapter is the "exam drill" companion to the Matrix Chain Multiplication chapter. We take the same DP, but we (1) fill the table cell by cell with every arithmetic step shown, (2) count how many parenthesizations exist (Catalan numbers), (3) state the complexity bounds precisely, and (4) extend the same "interval DP" idea to the Optimal Binary Search Tree (OBST) problem, which is the standard follow-up question in GATE.
We must multiply a chain of matrices . Matrix multiplication is associative, so the result is the same for every parenthesization, but the number of scalar multiplications differs enormously.
Dimensions. Matrix has dimension . So the dimension array has entries .
Cost of one product. Multiplying a matrix by a matrix costs scalar multiplications (and produces an matrix).
Goal. Choose the parenthesization minimizing total scalar multiplications.
The recurrence (with every symbol defined)
Let = minimum number of scalar multiplications needed to compute the product (for ).
Symbols:
- — first and last matrix index in the subchain (1-based).
- — the split point: we compute and , then multiply the two results.
- — optimal costs of the two subchains.
- — cost of the final multiplication: left result is , right result is , product costs .
Let = the that achieves the minimum (used to reconstruct the parenthesization).
Order of filling: by increasing chain length , from up to . (Length 1 is the base case.)