| Knapsack Problem |
Article Index for Knapsack |
Website Links For Problem |
Information AboutKnapsack Problem |
| CATEGORIES ABOUT KNAPSACK PROBLEM | |
| cryptography | |
| np-complete problems | |
| problems | |
| operations research | |
|
(The solution in this case is to choose all of the boxes besides the green one.)]] The knapsack problem is a problem in Combinatorial Optimization . It derives its name from the maximization problem of choosing possible essentials that can fit into one bag (of maximum weight) to be carried on a trip. A similar problem very often appears in business, Combinatorics , Complexity Theory , Cryptography and Applied Mathematics . Given a set of items, each with a cost and a value, then determine the number of each item to include in a collection so that the total cost is less than some given cost and the total value is as large as possible. The Decision Problem form of the knapsack problem is the question "can a value of at least ''V'' be achieved without exceeding the cost ''C''?" DEFINITION In the following, we have kinds of items, 1 through . Each item has a value and a weight . The maximum weight that we can carry in the bag is . The 0-1 knapsack problem restricts the number of each kind of item, , to zero or one. :Mathematically the 0-1-knapsack problem can be formulated as: :maximize :subject to The bounded knapsack problem restricts the number of each item to a specific value. :Mathematically the bounded knapsack problem can be formulated as: :maximize :subject to The unbounded knapsack problem places no bounds on the number of each item. Of particular interest is the special case of the problem with these properties:
Notice that in this special case, the problem is equivalent to this: given a set of integers, does any subset of it add up to exactly ''C''? Or, if negative costs are allowed and ''C'' is chosen to be zero, the problem is: given a set of integers, does any subset add up to exactly 0? This special case is called the Subset Sum Problem . For some reason, it is traditional in Cryptography to say "knapsack problem" when it is actually the "subset sum problem" that is meant. The knapsack problem is often solved using Dynamic Programming , though no polynomial-time algorithm is known for the general problem. Both the general knapsack problem and the subset sum problem are NP-hard , and this has led to attempts to use subset sum as the basis for Public Key Cryptography systems, such as Merkle-Hellman . These attempts typically used some Group other than the integers. Merkle-Hellman and several similar algorithms were later broken, because the particular subset sum problems they produced were in fact solvable by Polynomial-time Algorithms . The decision version of the knapsack problem described above is NP-complete and is in fact one of Karp's 21 NP-complete Problems . DYNAMIC PROGRAMMING SOLUTION The knapsack problem can be solved in Pseudo-polynomial Time using Dynamic Programming . The following depicts a dynamic programming solution for the ''unbounded knapsack problem''. Let the costs be ''c1'', ..., ''cn'' and the corresponding values ''v1'', ..., ''vn''. We wish to maximize total value subject to the constraint that total cost is less than or equal to ''C''. Then for each ''i'' ≤ ''C'', define ''A''(''i'') to be the maximum value that can be attained with total cost less than or equal to ''i''. Clearly, ''A''(''C'') is the solution to the problem. Define ''A''(''i'') recursively as follows:
|
|
|