Instead of using the brute force approach, we use the dynamic programming approach to obtain the optimal solution.The 0-1 knapsack problem is an important NP-hard problem that admits fully polynomial-time approximation schemes (FPTASs). The brute force approach has O(2 N) exponential running time. We have two options either we select or exclude the item. Another approach is to sort the items by cost per unit weight and starts from the highest until the knapsack is full.The greedy approach does not provide the optimal result in this problem.Here, we have to decide whether we have to take the item, i.e., x = 1 or not, i.e., x = 0. ![]()
0 Comments
Leave a Reply. |