Skip to content
Official PYQ · 2010

GATE CS 2010 Q34 — Algorithm Design: Dynamic Programming

Explain with AI

The weight of a sequence a0,a1,…,an−1a_0,a_1, \dots, a_{n-1} of real numbers is defined as a0+a1/2+⋯+an−1/2n−1a_0+a_1/2+ \dots + a_{n-1}/2^{n-1}. A subsequence of a sequence is obtained by deleting some elements from the sequence, keeping the order of the remaining elements the same. Let XX denote the maximum possible weight of a subsequence of ao,a1,…,an−1a_o,a_1, \dots, a_{n-1} and YY the maximum possible weight of a subsequence of a1,a2,…,an−1a_1,a_2, \dots, a_{n-1}. Then XX is equal to

Choose one option
View worked solution

Answer: B

To find the relation between XX and YY, we can analyze the structure of the optimal subsequence of a0,a1,…,an−1a_0, a_1, \dots, a_{n-1}.

Let SS be any subsequence of a1,a2,…,an−1a_1, a_2, \dots, a_{n-1} with elements s0,s1,…,sk−1s_0, s_1, \dots, s_{k-1}. By definition, the weight of SS is:

W(S)=s0+s12+s222+⋯+sk−12k−1W(S) = s_0 + \frac{s_1}{2} + \frac{s_2}{2^2} + \dots + \frac{s_{k-1}}{2^{k-1}}

The maximum possible weight of such a subsequence is Y=max⁡SW(S)Y = \max_{S} W(S).

Now, let TT be a subsequence of the entire sequence a0,a1,…,an−1a_0, a_1, \dots, a_{n-1}. There are two mutually exclusive and exhaustive cases for TT:

  1. Case 1: a0a_0 is not included in TT.
    In this case, TT is entirely a subsequence of a1,a2,…,an−1a_1, a_2, \dots, a_{n-1}.
    The maximum possible weight of TT in this case is simply YY.

  2. Case 2: a0a_0 is included in TT.
    Since a0a_0 is the first element of the original sequence, it must be the first element of TT. Thus, TT can be written as a0a_0 followed by some subsequence S=s0,s1,…,sk−1S = s_0, s_1, \dots, s_{k-1} of a1,a2,…,an−1a_1, a_2, \dots, a_{n-1}.
    The weight of TT is: W(T)=a0+s02+s122+⋯+sk−12k=a0+12(s0+s12+⋯+sk−12k−1)=a0+W(S)2W(T) = a_0 + \frac{s_0}{2} + \frac{s_1}{2^2} + \dots + \frac{s_{k-1}}{2^k} = a_0 + \frac{1}{2} \left( s_0 + \frac{s_1}{2} + \dots + \frac{s_{k-1}}{2^{k-1}} \right) = a_0 + \frac{W(S)}{2} To maximize W(T)W(T), we must maximize W(S)W(S), which yields YY.
    Therefore, the maximum possible weight of TT in this case is a0+Y2a_0 + \frac{Y}{2}.

Since the overall maximum weight XX must be the maximum over these two cases, we get:

X=max⁡(Y,a0+Y2)X = \max\left(Y, a_0 + \frac{Y}{2}\right)

Thus, the correct option is B.

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

Published
Report a correction
Keep exploringMore Algorithm Design: Dynamic Programming questions