GATE / CS ARCHIVE

GATE CSE 2018 / QUESTION 31

Optimal matrix-chain multiplication

Algorithms · Dynamic Programming · Full GATE CSE 2018 paper

GATE 2018, Q31 2 marks · MCQ
Report issue

Dynamic Programming

Question 31, GATE 2018: Matrices F1…F5 have dimensions 2×25,25×3,3×16,16×1,1×1000. Multiplying p×q by q×r costs pqr scalar operations. Which adjacent original pairs are directly multiplied in an optimal parenthesization? A F1F2 and F3F4; B F2F3; C F3F4; D F1F2 and F4F5.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Step through it (12 steps)

Method

The dynamic-programming state M[i,j] is the minimum scalar cost of multiplying the consecutive subchain; a split k adds the costs of its two subchains and their final product. This systematically tests all parenthesizations without a local greedy assumption. In the winning chain, F3F4 first produces 3×1 at cost 48; F2 times that gives 25×1 at cost 75; F1 times that gives 2×1 at cost 50; multiplying F5 costs 2000. Only the first operation multiplies two original matrices directly.

Solution

Use matrix-chain DP: M[i, j]=mink(M[i, k]+M[k+1, j]+d[i−1]d[k]d[j]). Dimensions are 2, 25, 3, 16, 1, 1000. Pair costs are 150, 1200, 48, 16000; three-matrix optimal costs 246, 123, 3048; four-matrix costs 173, 25123. Splitting the full chain after F1, F2, F3, F4 costs 75123, 9198, 48246, 2173 respectively. The unique optimum is((F1(F2(F3F4)))F5), costing 48+75+50+2000=2173. Its only directly multiplied original pair is F3F4, C.

Original paper, page 13 · Answer key