Proofs: Knapsack branch and bound
These are the human proofs of Knapsack branch and bound, at full length.
Knapsack branch and bound returns an optimal packing full
This proof shows: correctness, termination.
We use the pseudocode of the page. The items are sorted so that , with items of weight 0 first. For , a set extends a node if . A set is feasible if its weight is at most . Let be the largest value of over sets with .
Lemma 1 (the bound is valid). If , then , where is the bound rounded down.
Proof. Let . A fractional packing of items is a vector with . Let be the greedy vector: for items , for the first item that does not fit, and after it (if all items fit, is all ones). We show that maximizes . Let be any fractional packing, and let (or if all items fit). For , and ; for , and . So
when exists, because then ; when all items fit, for all and the sum is clearly nonnegative. Items of weight 0 are first and have . A 0-1 packing is a fractional packing, so , the unrounded bound. The left side is an integer, so it is also at most the rounded-down bound .
Lemma 2 (the take child keeps the bound). If , then .
Proof. The greedy fill from item with room takes item whole, because , and then continues on items with room . This is the greedy fill of the child, and the value moves from the fill into .
Claim 3 (the incumbent is real). At each point, is a feasible set of value . Proof. Initially and . Each pushed node has (the root has , the leave child keeps , and line L9 tests the take child), and and are the weight and value of . Line L5 copies such a node.
Claim 4 (invariant). At the start of each iteration of line L3, every feasible set with value greater than extends some node on .
Proof. At the start, holds the root, which every set extends. Suppose the claim holds at the start of an iteration. Let be the node popped, the incumbent before line L5, and the incumbent at the end of the iteration. Let be feasible with value greater than ; it extends a node that was on . If that node is not , it is still on . Suppose it is , so , and the value of is at most by Lemma 1.
- If , then , and line L5 gives , the value of : false.
- If at line L6: false, as the value of is at most .
- If , then extends the leave child; its value is at most , so this bound is greater than and line L7 pushes the child.
- If , then the weight of , so line L9 pushes the take child, which extends.
So the claim holds at the start of the next iteration.
Claim 5 (termination). Each pushed node has a larger than its parent, and , so each node of the binary tree of decisions is pushed at most once and the loop runs at most times.
Theorem. KNAPSACK-BB returns where is an optimal packing and its value.
Proof. The loop ends by Claim 5 with empty. By Claim 4, no feasible set has value greater than . By Claim 3, is feasible with value . So is optimal. The implementation sorts the items first and maps the indices of back to the input order, which changes neither feasibility nor value.