Question

Assume that multiplying a matrix G1G_1 of dimension p×qp \times q with another matrix G2G_2 of dimension q×rq \times r requires pqrpqr scalar multiplications. Computing the product of nn matrices G1G2G3…GnG_1 G_2 G_3 \dots G_n can be done by parenthesizing in different ways. Define GiGi+1G_i G_{i+1} as an explicitly computed pair for a given parenthesization if they are directly multiplied. For example, in the matrix multiplication chain G1G2G3G4G5G6G_1 G_2 G_3 G_4 G_5 G_6 using parenthesization (G1(G2G3))(G4(G5G6))(G_1(G_2 G_3))(G_4(G_5 G_6)), G2G3G_2 G_3 and G5G6G_5 G_6 are the only explicitly computed pairs.

Consider a matrix multiplication chain F1F2F3F4F5F_1 F_2 F_3 F_4 F_5, where matrices F1,F2,F3,F4F_1, F_2, F_3, F_4 and F5F_5 are of dimensions 2×252 \times 25, 25×325 \times 3, 3×163 \times 16, 16×116 \times 1 and 1×10001 \times 1000, respectively. In the parenthesization of F1F2F3F4F5F_1 F_2 F_3 F_4 F_5 that minimizes the total number of scalar multiplications, the explicitly computed pairs is/are

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

Solution

Use dynamic programming for matrix chain multiplication to find the parenthesization that minimizes scalar multiplications.

Given matrix dimensions d=[2,25,3,16,1,1000]d = [2, 25, 3, 16, 1, 1000] for matrices F1,F2,F3,F4,F5F_1, F_2, F_3, F_4, F_5:

  • F1:2×25F_1: 2 \times 25
  • F2:25×3F_2: 25 \times 3
  • F3:3×16F_3: 3 \times 16
  • F4:16×1F_4: 16 \times 1
  • F5:1×1000F_5: 1 \times 1000

Compute costs for subchains:

  • Chain length 2:
    • F1F2F_1 F_2: 2×25×3=1502 \times 25 \times 3 = 150
    • F2F3F_2 F_3: 25×3×16=120025 \times 3 \times 16 = 1200
    • F3F4F_3 F_4: 3×16×1=483 \times 16 \times 1 = 48
    • F4F5F_4 F_5: 16×1×1000=1600016 \times 1 \times 1000 = 16000
  • Chain length 3:
    • F1..F3F_1..F_3: min⁡((F1F2)F3:150+2×3×16=246,  F1(F2F3):1200+2×25×16=2000)=246\min((F_1 F_2)F_3: 150 + 2 \times 3 \times 16 = 246,\; F_1(F_2 F_3): 1200 + 2 \times 25 \times 16 = 2000) = 246
    • F2..F4F_2..F_4: min⁡((F2F3)F4:1200+25×16×1=1600,  F2(F3F4):48+25×3×1=123)=123\min((F_2 F_3)F_4: 1200 + 25 \times 16 \times 1 = 1600,\; F_2(F_3 F_4): 48 + 25 \times 3 \times 1 = 123) = 123 (split at F2(F3F4)F_2(F_3 F_4))
    • F3..F5F_3..F_5: min⁡((F3F4)F5:48+3×1×1000=3048,  F3(F4F5):16000+3×16×1000=64000)=3048\min((F_3 F_4)F_5: 48 + 3 \times 1 \times 1000 = 3048,\; F_3(F_4 F_5): 16000 + 3 \times 16 \times 1000 = 64000) = 3048
  • Chain length 4:
    • F1..F4F_1..F_4: min⁡(F1(F2..F4):0+123+2×25×1=173,  (F1..F3)F4:246+2×16×1=278)=173\min(F_1(F_2..F_4): 0 + 123 + 2 \times 25 \times 1 = 173,\; (F_1..F_3)F_4: 246 + 2 \times 16 \times 1 = 278) = 173 with structure F1(F2(F3F4))F_1(F_2(F_3 F_4))
  • Chain length 5 (F1..F5F_1..F_5):
    • Split (F1..F4)F5(F_1..F_4)F_5: 173+0+2×1×1000=2173173 + 0 + 2 \times 1 \times 1000 = 2173.
    • Any split involving F5F_5 earlier incurs much higher costs (e.g., F4F5F_4 F_5 alone is 16000).

The optimal parenthesization is ((F1(F2(F3F4)))F5)((F_1 (F_2 (F_3 F_4))) F_5) with total cost 2173.
In this parenthesization, the only base matrices multiplied directly together without an intermediate product are F3F_3 and F4F_4 (F3F4F_3 F_4).

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 2018 Computer Science and Information Technology (CS)
Question
41 of 65, printed as CS Q.31
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.