Data Structures & AlgorithmsModerateTCS NQT · Infosys pattern

Matrices A (10 × 20), B (20 × 30) and C (30 × 40) are to be multiplied. What is the minimum number of scalar multiplications?

  1. A. 8000
  2. B. 32000
  3. C. 24000
  4. D. 18000

Correct answer: D. 18000

(AB)C costs 10·20·30 + 10·30·40 = 6000 + 12000 = 18000; A(BC) costs 20·30·40 + 10·20·40 = 24000 + 8000 = 32000. So the left-to-right order is cheaper.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic