Skip to content
Official PYQ · 2021

GATE CS 2021 Set 1 Q40 — Algorithm Design: Greedy Techniques

Explain with AI

Define RnR_n to be the maximum amount earned by cutting a rod of length nn meters into one or more pieces of integer length and selling them. For i>0i>0, let p[i]p[i] denote the selling price of a rod whose length is ii meters. Consider the array of prices:

p[1]=1,p[2]=5,p[3]=8,p[4]=9,p[5]=10,p[6]=17,p[7]=18\text{p}[1]=1,\text{p}[2]=5,\text{p}[3]=8,\text{p}[4]=9,\text{p}[5]=10,\text{p}[6]=17,\text{p}[7]=18Which of the following statements is/are correct about R7R_7?

Select all correct options
View worked solution

Answer: A;C

Using the dynamic programming approach for the rod cutting problem, the maximum revenue RnR_n for a rod of length nn is given by:

Rn=max⁡1≤i≤n{p[i]+Rn−i}with R0=0R_n = \max_{1 \le i \le n} \{ p[i] + R_{n-i} \} \quad \text{with } R_0 = 0

Let's compute RiR_i step-by-step for i=1i = 1 to 77:

  • R1=p[1]=1R_1 = p[1] = 1
  • R2=max⁡(p[2],p[1]+R1)=max⁡(5,1+1)=5R_2 = \max(p[2], p[1] + R_1) = \max(5, 1 + 1) = 5
  • R3=max⁡(p[3],p[1]+R2,p[2]+R1)=max⁡(8,1+5,5+1)=8R_3 = \max(p[3], p[1] + R_2, p[2] + R_1) = \max(8, 1 + 5, 5 + 1) = 8
  • R4=max⁡(p[4],p[1]+R3,p[2]+R2,p[3]+R1)=max⁡(9,1+8,5+5,8+1)=10R_4 = \max(p[4], p[1] + R_3, p[2] + R_2, p[3] + R_1) = \max(9, 1 + 8, 5 + 5, 8 + 1) = 10
  • R5=max⁡(p[5],p[1]+R4,p[2]+R3,p[3]+R2,p[4]+R1)=max⁡(10,1+10,5+8,8+5,9+1)=13R_5 = \max(p[5], p[1] + R_4, p[2] + R_3, p[3] + R_2, p[4] + R_1) = \max(10, 1 + 10, 5 + 8, 8 + 5, 9 + 1) = 13
  • R6=max⁡(p[6],p[1]+R5,p[2]+R4,p[3]+R3,p[4]+R2,p[5]+R1)=max⁡(17,1+13,5+10,8+8,9+5,10+1)=17R_6 = \max(p[6], p[1] + R_5, p[2] + R_4, p[3] + R_3, p[4] + R_2, p[5] + R_1) = \max(17, 1 + 13, 5 + 10, 8 + 8, 9 + 5, 10 + 1) = 17
  • R7=max⁡(p[7],p[1]+R6,p[2]+R5,p[3]+R4,p[4]+R3,p[5]+R2,p[6]+R1)=max⁡(18,18,18,18,17,15,18)=18R_7 = \max(p[7], p[1] + R_6, p[2] + R_5, p[3] + R_4, p[4] + R_3, p[5] + R_2, p[6] + R_1) = \max(18, 18, 18, 18, 17, 15, 18) = 18

Thus, R7=18R_7 = 18. This makes Statement A correct and Statement B incorrect.

Now, let's identify all partitions of length 77 that yield a total revenue of 1818:

  1. 1 piece: {7}\{7\} with revenue p[7]=18p[7] = 18
  2. 2 pieces: {6,1}\{6, 1\} with revenue p[6]+p[1]=17+1=18p[6] + p[1] = 17 + 1 = 18
  3. 3 pieces: {3,2,2}\{3, 2, 2\} with revenue p[3]+p[2]+p[2]=8+5+5=18p[3] + p[2] + p[2] = 8 + 5 + 5 = 18

Since there are exactly three different solutions that achieve R7=18R_7 = 18, Statement C is correct. Because one of these solutions consists of three pieces, Statement D is incorrect.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Algorithm Design: Greedy Techniques questions