Sail E0 Webinar
Question
Consider the following dynamic programming implementation of the Knapsack problem:#includeint find_max(int a, int b){      if(a > b)         return a;      return b;}int knapsack(int W, int *wt, int *val,int n){     int ans[n + 1][W + 1];     int itm,w;     for(itm = 0; itm
Options:
A .  find_max(ans[itm "“ 1][w "“ wt[itm "“ 1]] + val[itm "“ 1], ans[itm "“ 1][w])
B .  find_max(ans[itm "“ 1][w "“ wt[itm "“ 1]], ans[itm "“ 1][w])
C .  ans[itm][w] = ans[itm "“ 1][w];
D .  none of the mentioned
Answer: Option A


find_max(ans[itm “ 1][w “ wt[itm “ 1]] + val[itm “ 1], ans[itm “ 1][w]) completes the above code.



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

More Questions on This Topic :


Latest Videos

Latest Test Papers