-2

I wonder the best and the worst case scenarios for the knapsack problem. I guess the best case should be the values and the weights for all of the objects have the same values. For example:

int[] values = new int[] { 5, 5, 5};
int[] weights = new int[] { 9, 9, 9}; 

But I don't have any idea about the worst case.

Thank you so much!

  • There is no worst-case without an algorithm to be used to optimize it. So the worst-case depends on assumptions about this algorithm and i expect lots of differences between dynamic-programming, integer-programming or constraint-programming. Most of the reasoning will be very tough: there might be cases, where it's not about box-statistics of your values, but number-theory like characteristics -> only prime-weights. One algorithm will really struggle, while another will not care. It's easy to build a *surprisingly usable solver* which completely breaks with your *best-case* ("unit"). – sascha Apr 11 '20 at 20:55
  • https://en.wikipedia.org/wiki/Knapsack_problem#Computational_complexity – Jim Mischel Apr 12 '20 at 04:48

1 Answers1

0

Since best and worst case scenarios are defined relative to algorithms or solutions to problems, I assume that you are referring to the well-known dynamic programming solution to the knapsack problem.

The dynamic programming solution to the knapsack algorithm is a pseudo-polynomial algorithm that runs in O(nW) time, where n denotes the number of items and W denotes the maximum weight. Thus, you can make this algorithm run very poorly by simply setting the maximum weight to an arbitrarily high value. In particular, setting each weight to 2^n would make this algorithm run in O(2^n) time.

Ekesh Kumar
  • 495
  • 4
  • 12