Question: The following code is executed with some value of the knapsack problem. Here W = knapsack size, wt is weight of the items, val is
The following code is executed with some value of the knapsack problem. Here W = knapsack size, wt is weight of the items, val is value of the items and n is number of items. After execution the content of the S array is also given. Analyzing this information and write down which item(s) are selected and whether knapsack is fully or partially filled after the process.

int knapsack(int w, int wt[], int val[], int n) int i, w; int K[100] [100]; int S[100] (100); for (i = 0; i Ki 1] [w]) { K[i] [w] = valci 1] + K[i - 1] [W - wt[i-1]); S[i][W] = wt[i - 1]; } else K[i][w] = K[i - 1] [w]: S[i][w] = 0; } 1 1 else K[i] [W] = K[i 1] [W]; S[i][w] = 0; } printf ("50", S[i][w]); } printf(" "); } @ @ @ @ @ @ 4 4 3 4 3 3 3 @ 4 3 @ 4 @ 4 3 @ 4 @ 4 3 7 4 6 e 4 3 7 4 4 3 @ 4 @ @ 4 3 7 4 @ @ @ 4 @ 4 @ 4 @ @
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
