Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

Matrices A1 to A6 have dimension sequence p = [30, 35, 15, 5, 10, 20, 25] (matrix i is p[i−1] × p[i]). What is the minimum number of scalar multiplications needed to compute the product A1·A2·…·A6, choosing the parenthesisation optimally?

  1. A. 15125
  2. B. 40500
  3. C. 16125
  4. D. 140

Correct answer: A. 15125

Interval DP: best[i][j] = min over split k of best[i][k] + best[k+1][j] + p[i]·p[k+1]·p[j+1]. Multiplying left to right follows the chain as written and can cost many times more than the optimal bracketing.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic