A Polynomial-Time Algorithm for the Knapsack Problem with Two Variables

D. S. Hirschberg, C. K. Wong
1976 Journal of the ACM  
The general knapsack problem is known to be NP-complete In this paper a very special knapsack problem is studied, namely, one with only two variables. A polynomial-time algorithm is presented and analyzed However, ~t remains an open problem that for any fixed n > 2, the knapsack problem with n variables can be solved in polynomial time. KEY WORDS AND PHRASES: knapsack problem, polynomial-time algorithm, integer optimization, continued fraction approximation CR CATEGOR~S 5.25, 5.30 Introductwn
more » ... 5.30 Introductwn The knapsack problem considered here is the following: (1) and X, nonnegative integers, where a" c" b are positive real numbers. It can be shown [6] that this problem is NPcomplete in the sense of Karp [4, 5] . Recently, polynomial-time appromma~e solutions to the special case when X, is restricted to 0, 1 have been obtained [7] In fact, polynomialtime approximate solutions to the general case when X, is not restricted can be obtained in a similar fashion. In this paper we follow another approach; namely, we fix the number of variables n and look for polynomial-time optimum solutions to the knapsack problem of n variables Although our attempt to solve this problem in general has been unsuccessful, ~ e have found an algorithm for the case n = 2, which runs in polynomial time of the length of the input. More specifically, we shall solve the following problem: maximize clX~ ~ c~X2 subject to alX~ -}-a~X2 _< b (2) and X1, X2 nonnegative integers Note that the naive approach (test X1 = ~, X~ = [(b --al~)/a2] as i takes on integer values from 0 to [b/al] ) takes time proportional to b/a~ which is exponential in the length of the input
doi:10.1145/321921.321936 fatcat:bmeb6nfet5hv7cu4b2hzcj33qq