Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose you are given a set S of tuples = {(v_1, p_1), (v_2, p_2), ..., (v_n, p_

ID: 3824483 • Letter: S

Question

Suppose you are given a set S of tuples = {(v_1, p_1), (v_2, p_2), ..., (v_n, p_n)} and an integer X. Your goal is to a find a set T {1, 2, ..., n} such that sigma_i elementof T p_i is maximized (over all possible choices of T) subject to the constraints sigma_i T v_i lessthanorequalto X. Your goal is to design an algorithm, using Dynamic Programming, that gets S and X as input, and outputs such T. Write the recurrence relation for this problem. Design an iterative algorithm (based on the recurrence relation) to solve the problem. Analyze the run-time of your algorithm.

Explanation / Answer

(i)

We wanted to find a subset of S having maximum to weight. So always calculating maximum
weight-value pairs.
Recurrence relation will be..

cost[ i, w ] = cost[ i – 1, w ] if, Wi > w
cost[ i, w ] = max( cost[ i – 1, w ], cost[ i – 1, w – Wi ] ) if, Wi <= w

(ii)

MaximizeTupleDP(v,w,n,X)
{
   for(w=0 to X)DP[0,w] = 0;
       for(j=1 to n)
           for(w=0 to X)
               if(w[j] <= w)
DP[j,w] = max{DP[j-1,w],v[j]+DP[j-1,w-w[j]]};
               else
DP[j,w] = DP[j-1,w];
   return DP[n,X];          
}

(iii)

Complexity O(n*X)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote