Question: Now, you are given the following items with their corresponding weights and values: item 3. 4 8. 9. weight value 40 6. 12 24 4.
Now, you are given the following items with their corresponding weights and values: item 3. 4 8. 9. weight value 40 6. 12 24 4. 10 18 23 9. 12 7. 13 Propose a change to the above solution so it runs quicker for this given input. What would be the new performance after applying the proposed change? (a). Briefly describe the changes you want to make (6 pts): (b). After applying the changes you have proposed, what is the performance now, in relation to the original performance (2 pts)? Answer: orivate int DP(int[] weight, int[] val, int capacity)( int[J0 value - new int[val.length+1][capacity+1]; for ( int i = 0; i w ) value[i][w] = value[i-1][w]; else value[i][w] - Math.max(value[i-1][w], val[i-1] + value[i-1][w-weight[1-1]]); return value[val.length][capacity]; Now, you are given the following items with their corresponding weights and values: item 3. 4 8. 9. weight value 40 6. 12 24 4. 10 18 23 9. 12 7. 13 Propose a change to the above solution so it runs quicker for this given input. What would be the new performance after applying the proposed change? (a). Briefly describe the changes you want to make (6 pts): (b). After applying the changes you have proposed, what is the performance now, in relation to the original performance (2 pts)? Answer: orivate int DP(int[] weight, int[] val, int capacity)( int[J0 value - new int[val.length+1][capacity+1]; for ( int i = 0; i w ) value[i][w] = value[i-1][w]; else value[i][w] - Math.max(value[i-1][w], val[i-1] + value[i-1][w-weight[1-1]]); return value[val.length][capacity]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
