Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

A chain of 6 matrices M1 to M6 has dimensions given by the sequence p = [20, 8, 2, 10, 19, 2, 7], where Mi has size p[i−1] × p[i] (1-indexed). Multiplying two matrices of sizes a×b and b×c costs a·b·c scalar multiplications. What is the minimum total number of scalar multiplications over all parenthesisations?

  1. A. 5560
  2. B. 3436
  3. C. 2968
  4. D. 1048

Correct answer: D. 1048

The interval DP gives 1048. Multiplying strictly left to right costs 5560; the greedy 'cheapest adjacent pair first' rule gives 3436, which is not optimal.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic