Skip to content
Official PYQ · 2011

GATE CS 2011 Q38 — Algorithm Design: Dynamic Programming

Explain with AI

Four Matrices M1,M2,M3M_1, M_2, M_3 and M4M_4 of dimensions p×q,  q×r,  r×sp \times q, \:\:q \times r, \:\:r \times s and s×ts \times t respectively can be multiplied in several ways with different number of total scalar multiplications. For example when multiplied as ((M1×M2)×(M3×M4))((M_1 \times M_2) \times (M_3 \times M_4)), the total number of scalar multiplications is pqr+rst+prtpqr + rst + prt. When multiplied as (((M1×M2)×M3)×M4)(((M_1 \times M_2) \times M_3) \times M_4), the total number of scalar multiplications is pqr+prs+pstpqr + prs + pst.

If p=10,q=100,r=20,s=5p=10, q=100, r=20, s=5 and t=80t=80, then the minimum number of scalar multiplications needed is

Choose one option
View worked solution

Answer: C

The dimensions of the four matrices are:

  • M1:10×100M_1: 10 \times 100
  • M2:100×20M_2: 100 \times 20
  • M3:20×5M_3: 20 \times 5
  • M4:5×80M_4: 5 \times 80

For 44 matrices, there are 55 possible parenthesizations. Let's evaluate the most promising ones to find the minimum cost:

Case 1: (M1×(M2×M3))×M4(M_1 \times (M_2 \times M_3)) \times M_4

  • Cost of (M2×M3)(M_2 \times M_3) [resulting in a 100×5100 \times 5 matrix]:
    100×20×5=10000100 \times 20 \times 5 = 10000
  • Cost of M1×(M2×M3)M_1 \times (M_2 \times M_3) [resulting in a 10×510 \times 5 matrix]:
    10×100×5=500010 \times 100 \times 5 = 5000
  • Cost of multiplying the result with M4M_4:
    10×5×80=400010 \times 5 \times 80 = 4000
  • Total cost = 10000+5000+4000=1900010000 + 5000 + 4000 = 19000

Case 2: ((M1×M2)×M3)×M4((M_1 \times M_2) \times M_3) \times M_4

  • Cost of (M1×M2)(M_1 \times M_2) [resulting in a 10×2010 \times 20 matrix]:
    10×100×20=2000010 \times 100 \times 20 = 20000
  • Cost of multiplying with M3M_3 [resulting in a 10×510 \times 5 matrix]:
    10×20×5=100010 \times 20 \times 5 = 1000
  • Cost of multiplying with M4M_4:
    10×5×80=400010 \times 5 \times 80 = 4000
  • Total cost = 20000+1000+4000=2500020000 + 1000 + 4000 = 25000

Evaluating other parenthesizations yields even larger values (e.g., (M1×M2)×(M3×M4)(M_1 \times M_2) \times (M_3 \times M_4) costs 4400044000). Thus, the minimum number of scalar multiplications is 1900019000.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Algorithm Design: Dynamic Programming questions