GateAI
Dynamic Programming

GATE CSE 2016 Set 2 · Q38

NAT2 marksMedium

Time

Let A1,A2,A3A_1, A_2, A_3, and A4A_4 be four matrices of dimensions 10×5,5×20,20×1010 \times 5, 5 \times 20, 20 \times 10, and 10×510 \times 5, respectively. The minimum number of scalar multiplications required to find the product A1A2A3A4A_1A_2A_3A_4 using the basic matrix multiplication method is _______.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 1500

Dynamic Programming

Let the sequence of dimensions be p=⟨p0,p1,p2,p3,p4⟩=⟨10,5,20,10,5⟩p = \langle p_0, p_1, p_2, p_3, p_4 \rangle = \langle 10, 5, 20, 10, 5 \rangle.

Using dynamic programming for Matrix Chain Multiplication, let m[i,j]m[i, j] denote the minimum number of scalar multiplications needed to compute Ai…AjA_i \dots A_j:

Chains of length 1:

  • m[1,1]=m[2,2]=m[3,3]=m[4,4]=0m[1, 1] = m[2, 2] = m[3, 3] = m[4, 4] = 0

Chains of length 2:

  • m[1,2]=p0p1p2=10×5×20=1000m[1, 2] = p_0 p_1 p_2 = 10 \times 5 \times 20 = 1000

  • m[2,3]=p1p2p3=5×20×10=1000m[2, 3] = p_1 p_2 p_3 = 5 \times 20 \times 10 = 1000

  • m[3,4]=p2p3p4=20×10×5=1000m[3, 4] = p_2 p_3 p_4 = 20 \times 10 \times 5 = 1000

Chains of length 3:

  • For m[1,3]m[1, 3]:

    • Split at k=1k=1: m[1,1]+m[2,3]+p0p1p3=0+1000+10×5×10=1500m[1, 1] + m[2, 3] + p_0 p_1 p_3 = 0 + 1000 + 10 \times 5 \times 10 = 1500

    • Split at k=2k=2: m[1,2]+m[3,3]+p0p2p3=1000+0+10×20×10=3000m[1, 2] + m[3, 3] + p_0 p_2 p_3 = 1000 + 0 + 10 \times 20 \times 10 = 3000

    • m[1,3]=1500m[1, 3] = 1500

  • For m[2,4]m[2, 4]:

    • Split at k=2k=2: m[2,2]+m[3,4]+p1p2p4=0+1000+5×20×5=1500m[2, 2] + m[3, 4] + p_1 p_2 p_4 = 0 + 1000 + 5 \times 20 \times 5 = 1500

    • Split at k=3k=3: m[2,3]+m[4,4]+p1p3p4=1000+0+5×10×5=1250m[2, 3] + m[4, 4] + p_1 p_3 p_4 = 1000 + 0 + 5 \times 10 \times 5 = 1250

    • m[2,4]=1250m[2, 4] = 1250

Chain of length 4 (m[1,4]m[1, 4]):

  • Split at k=1k=1: m[1,1]+m[2,4]+p0p1p4=0+1250+10×5×5=1250+250=1500m[1, 1] + m[2, 4] + p_0 p_1 p_4 = 0 + 1250 + 10 \times 5 \times 5 = 1250 + 250 = 1500

  • Split at k=2k=2: m[1,2]+m[3,4]+p0p2p4=1000+1000+10×20×5=2000+1000=3000m[1, 2] + m[3, 4] + p_0 p_2 p_4 = 1000 + 1000 + 10 \times 20 \times 5 = 2000 + 1000 = 3000

  • Split at k=3k=3: m[1,3]+m[4,4]+p0p3p4=1500+0+10×10×5=1500+500=2000m[1, 3] + m[4, 4] + p_0 p_3 p_4 = 1500 + 0 + 10 \times 10 \times 5 = 1500 + 500 = 2000

The minimum cost is min⁡(1500,3000,2000)=1500\min(1500, 3000, 2000) = 1500, corresponding to the parenthesization A1((A2A3)A4)A_1 ((A_2 A_3) A_4).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Dynamic Programming previous year question is Q38 of the GATE CSE 2016 Set 2 paper. Find more GATE CSE PYQs on Dynamic Programming in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Dynamic Programming PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Dynamic Programming in GATE CSE

Dynamic Programming has 7 GATE CSE PYQs across 6 papers from 2011 to 2026. 2 of them are 2-mark NAT questions like this one, and GATE CSE 2016 Set 2 has 2.

How GATE tests Dynamic Programming

More from GATE CSE 2016 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2016 Set 2 · Q38 · NAT

Let A1, A2, A3, and A4 be four matrices of dimensions 10 × 5, 5 × 20, 20 × 10, and 10 × 5, respectively. The minimum number of scalar multiplications required to find the product A1A2A3A4 using the basic matrix multiplication method is …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.