Question

Four matrices M1,M2,M3M_1, M_2, M_3 and M4M_4 of dimensions p×qp \times q, q×rq \times r, r×sr \times s and s×ts \times t respectively can be multiplied in several ways with different number of total scalar multiplications. For example when multiplied as ((M1×M2)×(M3×M4))((M_1 \times M_2) \times (M_3 \times M_4)), the total number of scalar multiplications is pqr+rst+prtp q r + r s t + p r t. When multiplied as (((M1×M2)×M3)×M4)(((M_1 \times M_2) \times M_3) \times M_4), the total number of scalar multiplications is pqr+prs+pstp q r + p r s + p s t.

If p=10,q=100,r=20,s=5p = 10, q = 100, r = 20, s = 5, and t=80t = 80, then the minimum number of scalar multiplications needed is

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2011 answer key

Solution

Apply the dynamic programming Matrix Chain Multiplication algorithm to find the optimal parenthesization cost.

  1. Matrix dimensions are given by array d=[10,100,20,5,80]d = [10, 100, 20, 5, 80], where matrix MiM_i has dimension di−1×did_{i-1} \times d_i for i∈{1,2,3,4}i \in \{1, 2, 3, 4\}.
  1. Chain length 2 costs:
  • m[1,2]=d0d1d2=10×100×20=20,000m[1, 2] = d_0 d_1 d_2 = 10 \times 100 \times 20 = 20,000
  • m[2,3]=d1d2d3=100×20×5=10,000m[2, 3] = d_1 d_2 d_3 = 100 \times 20 \times 5 = 10,000
  • m[3,4]=d2d3d4=20×5×80=8,000m[3, 4] = d_2 d_3 d_4 = 20 \times 5 \times 80 = 8,000
  1. Chain length 3 costs:
  • For m[1,3]m[1, 3]:
    • Split at 1: m[2,3]+d0d1d3=10,000+10×100×5=15,000m[2, 3] + d_0 d_1 d_3 = 10,000 + 10 \times 100 \times 5 = 15,000
    • Split at 2: m[1,2]+d0d2d3=20,000+10×20×5=21,000m[1, 2] + d_0 d_2 d_3 = 20,000 + 10 \times 20 \times 5 = 21,000
    • Minimum m[1,3]=15,000m[1, 3] = 15,000.
  • For m[2,4]m[2, 4]:
    • Split at 2: m[3,4]+d1d2d4=8,000+100×20×80=168,000m[3, 4] + d_1 d_2 d_4 = 8,000 + 100 \times 20 \times 80 = 168,000
    • Split at 3: m[2,3]+d1d3d4=10,000+100×5×80=50,000m[2, 3] + d_1 d_3 d_4 = 10,000 + 100 \times 5 \times 80 = 50,000
    • Minimum m[2,4]=50,000m[2, 4] = 50,000.
  1. Chain length 4 (m[1,4]m[1, 4]):
  • Split at 1: m[2,4]+d0d1d4=50,000+10×100×80=130,000m[2, 4] + d_0 d_1 d_4 = 50,000 + 10 \times 100 \times 80 = 130,000
  • Split at 2: m[1,2]+m[3,4]+d0d2d4=20,000+8,000+10×20×80=44,000m[1, 2] + m[3, 4] + d_0 d_2 d_4 = 20,000 + 8,000 + 10 \times 20 \times 80 = 44,000
  • Split at 3: m[1,3]+d0d3d4=15,000+10×5×80=15,000+4,000=19,000m[1, 3] + d_0 d_3 d_4 = 15,000 + 10 \times 5 \times 80 = 15,000 + 4,000 = 19,000
  1. The global minimum scalar multiplications needed is 19,000.
Final answer

C

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2011 Computer Science and Information Technology (CS)
Question
38 of 65, printed as CS Q.38
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.