GATE / CS ARCHIVE

SIMILAR QUESTIONS / ALGORITHMS

Optimize ordered matrix-chain parenthesization

3 questions solved the same way, newest first. Back to Algorithms

How these are solved

Use dimension-aware interval DP or enumerate legal ordered parenthesizations, charging pqr per product. 2011/2016 request the minimum scalar count for four matrices;

2 marks · MCQ
Report issue

Optimal matrix-chain multiplication

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

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

2 marks · MCQ
Report issue

Matrix-chain multiplication optimum

Dynamic Programming

Question 38, GATE 2011: Four matrices M1,M2,M3,M4 have dimensions 10×100,100×20,20×5,5×80. Multiplication of an a×b matrix by a b×c matrix costs abc scalar multiplications. What is the minimum total for their ordered product over all parenthesizations?

(A) 248000
(B) 44000
(C) 19000
(D) 25000
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Step through it (8 steps)

For dimensions 10, 100, 20, 5, 80, the five full parenthesizations have costs 25000 for(((AB)C)D), 19000 for((A(BC))D), 44000 for((AB)(CD)), 130000 for(A((BC)D)) and 248000 for(A(B(CD))). The minimum is 19000, attained by BC costing 100×20×5=10000, then A(BC) costing 10×100×5=5000, then the final product costing 10×5×80=4000. Thus C.

Label the matrices A,B,C,D. Dimensions of intermediate results matter: BC is 100×5, A(BC) is 10×5, and the final product is 10×80. Multiplying the dimensions of each operation yields the stated 10000+5000+4000 optimum. Checking all five full binary parenthesizations proves that this is a global minimum, not merely a good greedy choice. For example, doing AB first already costs 20000 before the remaining work, exceeding the optimum by itself.

Original paper, page 10 · Answer key