- Official answer
- 1500
- From
- Official GATE 2016 answer key
Solution
Apply dynamic programming to solve the Matrix Chain Multiplication problem for 4 matrices.
Given matrix dimensions:
- A1:10×5 (p0=10,p1=5)
- A2:5×20 (p2=20)
- A3:20×10 (p3=10)
- A4:10×5 (p4=5)
Dimension array: p=[10,5,20,10,5].
Let m[i,j] denote the minimum number of scalar multiplications required to compute Ai…Aj.
- Chains of length 2:
- m[1,2]=p0p1p2=10×5×20=1000
- m[2,3]=p1p2p3=5×20×10=1000
- m[3,4]=p2p3p4=20×10×5=1000
- Chains of length 3:
-
m[1,3]=min{m[1,1]+m[2,3]+p0p1p3=0+1000+10×5×10=1500,m[1,2]+m[3,3]+p0p2p3=1000+0+10×20×10=3000}=1500
-
m[2,4]=min{m[2,2]+m[3,4]+p1p2p4=0+1000+5×20×5=1500,m[2,3]+m[4,4]+p1p3p4=1000+0+5×10×5=1250}=1250
- Chain of length 4 (m[1,4]):
- Split at k=1: m[1,1]+m[2,4]+p0p1p4=0+1250+10×5×5=1250+250=1500
- Split at k=2: m[1,2]+m[3,4]+p0p2p4=1000+1000+10×20×5=2000+1000=3000
- Split at k=3: m[1,3]+m[4,4]+p0p3p4=1500+0+10×10×5=1500+500=2000
The minimum scalar multiplications required is:
m[1,4]=min(1500,3000,2000)=1500
This optimal cost corresponds to the parenthesization A1((A2A3)A4).
Common trapMultiplying left-to-right ((A1A2)A3)A4=1000+2000+500=3500, which is sub-optimal.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.