Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band

A chain of 6 matrices M1 to M6 has dimensions given by the sequence p = [16, 18, 7, 19, 14, 15, 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. 6916
  2. B. 6818
  3. C. 13440
  4. D. 7161

Correct answer: B. 6818

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic