Dynamic Programming
Dynamic Programming
By
Consider < A1 A2 A3 > chain where [A1]10 x 100, [A2]100 x 5, [A3]5 x 50.
((A1 A2) A3) requires 10 x 100 x 5 + 10 x 5 x 50 = 7500 scalar
multiplications.
(A1(A2 A3)) requires 100 x 5 x 50 + 10 x 100 x 50 = 75000 scalar
multiplications.
So ((A1 A2) A3) is 10 times faster than (A1(A2 A3)).
Problem Statement: Given a chain < A1, A2, A2, …, An > of n matrices,
where Ai has dimension pi-1pi, for i = 1…, n, fully parenthesize the
product in a way that minimizes the number of scalar multiplications.
1 , 𝑖𝑓 𝑛 = 1
P(n) = { 𝑛
∑𝑘=0 𝑃(𝑘)𝑃(𝑛 − 𝑘) , 𝑖𝑓 𝑛 >= 2
An Instance:
Problem Statement:
The fastest way through station S1, j−1 and then directly through station S1, j,
OR
The fastest way through station S2, j−1, a transfer from line 2 to line 1, and
then through station S1, j.
Using symmetric reasoning, the fastest way through station S2, j is either
The fastest way through station S2, j−1 and then directly through station S2, j,
OR
The fastest way through station S1, j−1, a transfer from line 1 to line 2, and
then through station S2, j.
Thus in General:
For j = 2, 3, . . . , n, we have,