Question: - 2.4. (10 pts) . An alternative algorithm for the knapsack problem is given below. Carefully explain how to computes its time complexity. int knapsack

- 2.4. (10 pts) . An alternative algorithm for the knapsack problem is given below. Carefully explain how to computes its time complexity. int knapsack (int v[], int m[], int n, int W) { if (n = 0 || W= 0) return 0; if (m[n] > W) return knapsack (v, m, n-1, W); if (v [n-1] + knapsack (v, m, n-1, W) > knapsack (v, m, n-1, W)) { return v [n-1] + knapsack (v, m, n-1, W); } else { return knapsack (v, m, n-1, W); } 1 }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
