GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Matrices A₁ … A₇ have dimensions 5×12, 12×7, 7×20, 20×4, 4×15, 15×9 and 9×6, i.e. the dimension array p = [5, 12, 7, 20, 4, 15, 9, 6]. What is the minimum number of scalar multiplications to compute A₁A₂…A₇?

  1. A. 2765
  2. B. 1996
  3. C. 3354
  4. D. 2210

Correct answer: B. 1996

The matrix-chain DP gives m[1][7] = 1996. Multiplying strictly left to right costs 2765 and strictly right to left costs 3354, so neither fixed order is optimal.

More Algorithms questions

Exams that ask this topic