Skip to content
Mad4Study

Engineering & Science

GATE Computer Science

  • GATE CS
  • 2026–27 pattern practice
  • Algorithms
  • Dynamic programming
  • Medium

Matrices A (10×2010 \times 20), B (20×3020 \times 30) and C (30×4030 \times 40) are to be multiplied as ABC. What is the minimum number of scalar multiplications needed?

Algorithm Design

Pick an option to check your answer.

There are two parenthesisations. (AB)C(AB)C costs 10⋅20⋅30+10⋅30⋅40=6,000+12,000=18,00010 \cdot 20 \cdot 30 + 10 \cdot 30 \cdot 40 = 6{,}000 + 12{,}000 = 18{,}000. A(BC)A(BC) costs 20⋅30⋅40+10⋅20⋅40=24,000+8,000=32,00020 \cdot 30 \cdot 40 + 10 \cdot 20 \cdot 40 = 24{,}000 + 8{,}000 = 32{,}000. The minimum is 18,00018{,}000, which is what the matrix-chain DP finds.

Why not the others

  • 32,00032{,}000 is the cost of A(BC)A(BC), the worse order.
  • 24,00024{,}000 is only the cost of computing BC.
  • 6,0006{,}000 is only the cost of computing AB.

Report an error

GATE CS · Algorithms · Algorithm Design