MCS 312: NP Completeness and Approximation Algorithms: Instructor Neelima Gupta Ngupta@cs - Du.ac - in
MCS 312: NP Completeness and Approximation Algorithms: Instructor Neelima Gupta Ngupta@cs - Du.ac - in
• 0-1 Knapsack
• Bin Packing
The Knapsack Problem
The classic Knapsack problem is:
A thief breaks into a store and wants to fill his
knapsack of capacity K with goods of as much value
as possible.
Proof: Suppose not. Let O be an optimal solution that does not contain
x1. Let xt be the item with maximum weight wt in O. If wt > w1,
replacing w1 amount of xt by w1 amount of x1, value of the solution
will improve (since v1/w1 > vt/wt).
If no such set S’ exists then (sum of all the sets in O =) W < = w1.
Replace all the sets in O by W amount of x1 and the value of the
solution will improve.
Other Simple versions
• By Generalization it is NPC
Further generalization of Subset
Sum
• Gen1_SS: Given a finite set S ={x1 … xn}
of n numbers, does there exist a subset S’
of S that whose sum is = K.
• Gen2_SS: Given a finite set S ={x1 … xn}
of n numbers, find a subset S’ of S that
maximizes the sum with the constraint that
the sum is <= K.
• Its decision version is: Given a finite set S
={x1 … xn} of n numbers, does there exist
a subset S’ of S whose sum >= W with the
constraint that the sum is <= K.
0-1 Knapsack is NP-Complete
• Gen2_SS: Given a finite set S ={x1 … xn}
of n numbers, find a subset S’ of S that
maximizes the sum with the constraint that
the sum is <= K.
• The above subset sum problem is a
particular case of 0-1 Knapsack by putting
wi = vi = xi. i.e. 0-1 Knapsack is a
generalization of the above subset sum
problem.
Bin Packing Problem
• Given a set of items S = {x1…xn} each
with some weight wi, pack maximum
number of items into a collection of finite
number of bins each with some capacity Bi
using minimum number of bins.