0

The typical objective function of 0-1 Multidimensional Knapsack is to maximize the value of all items in the knapsack. A good algorithm was provided in the Stackexchange link here: 0-1 Multidimensional Knapsack.

However, what if my objective function is to pack as many items in the knapsack as possible? All pieces have equal values. The Stackexchange post (Knapsack problem with all profits equal to 1) claims that a one dimensional knapsack with equal values can be solved by Greedy Algorithm. Is that true? I thought the 01 knapsack problem is NP-hard therefore the greedy algorithm may not give the optimum solution.

So my questions are two-part? 1) can optimum solution be given by greedy algorithm in this case? 01 knapsack with equal values 2) how to implement a multi-dimensional greedy algorithm? the vi/wi is a value divided by a vector...

Community
  • 1
  • 1
Wei Zhang
  • 1
  • 1

1 Answers1

2

1.) The knapsack problem IS an NP-Hard problem. So in short, no, you cannot solve it optimally using a greedy algorithm. Instead heuristic approaches exist that can get you very close.

2.) In the case of equal profit knapsack, this will likely to degrade to a simple bin packing problem. In this context if all choices are equal in terms of profit, you will likely need to focus on a different aspect of the problem which is probably something like "size." If that is the case you will want to pick the smallest item you can each time - in which case a greedy algorithm is probably sufficient and can be achieved by simply looking through your choices and choosing the smallest element.

It should be noted that a linear search can add an annoying amount of overhead to your program if its being repeated a great deal of times. Instead you may want to consider using a MIN-Heap as this will make the smallest value available at a lower computational cost.

MS-DDOS
  • 578
  • 5
  • 15