GATE / CS ARCHIVE

GATE CSE 2016 SET 2 / QUESTION 38

GATE CSE 2016 Set 2 Q38

Algorithms · Dynamic Programming · Full GATE CSE 2016 Set 2 paper

GATE 2016 Set 2, Q38 2 marks · NAT
Report issue

Dynamic Programming

Question 38, GATE 2016: Matrices A1,A2,A3,A4 have dimensions 10×5,5×20,20×10,10×5. Find the minimum number of scalar multiplications using ordinary matrix multiplication to compute their product.
Tap to enlarge
Answer & solution

Official answer: 1500.0 : 1500.0

Our answer: 1500

Step through it (8 steps)

Use A1((A2A3)A4): A2A3 costs 5·20·10=1000 and yields 5×10; multiplying A4 costs 5·10·5=250 and yields 5×5; multiplying A1 costs 10·5·5=250. Total 1500. The five full parenthesizations cost 1750, 1500, 3000, 2000, 3500, so 1500 is minimal.

Matrix-chain DP uses M(i,j)=min over k of M(i,k)+M(k+1,j)+di−1dk dj, with M(i,i)=0. For d=(10,5,20,10,5), two-matrix costs are 1000,1000,1000; three-matrix optima are M(1,3)=1500 and M(2,4)=1250. Splitting the full chain after A1 then costs 1250+250=1500.

Original paper, page 35 · Answer key