Which algorithm is best suited for solving the knapsack problem optimally?
18 views
- Greedy
- Backtracking
- Dynamic Programming (Correct Answer)
- Divide and Conquer
Explanation
Dynamic programming solves the knapsack problem by breaking it into subproblems and storing intermediate results. It ensures optimal solutions unlike greedy approaches which may fail for 0/1 knapsack.