I have obtained a proof that would discredit a generally held idea regarding the 0/1 knapsack problem and I'm really having a hard time convincing my self I am right because I couldn't find any thing any where to support my claims, so I am going to first state my claims and then prove them and I would appreciate anyone to try to substantiate my claims further or disproof them. Any collaboration is appreciated.
Assertions:
- The size of the bnb (branch and bound) algorithm for solving the knapsack problem is not independent of the K (capacity of the knapsack).
- The size of bnb tree complete space is always of O(NK) with N being the number of items and not O(2^N)
- The bnb algorithm is always better than the standard dynamic programming approach both in time and space.
Pre-assumptions: The bnb algorithm prone the invalid nodes (if the remaining capacity is less than the weight of current item, we are not going to extend it. Also, the bnb algorithm is done in a depth-first manner.
Sloppy Proof:
Here is the recursive formula for solving the knapsack problem:
Value(i,k) = max (Value(i-1,k) , Value(n-1 , k-weight(i)) + value(i)
however if k < weight(i): Value(i,k) = Value(i-1,k)
Now imagine this example:
K = 9
N = 3
V W:
5 4
6 5
3 2
Now here is the Dynamic solution and table for this problem:
Now imagine regardless of whether it is a good idea or not we want to do this using only the recursive formula through memoization and not with the table, with something like a map/dictionary or a simple array to store the visited cells. For solving this problem using memoization we should solve the denoted cells:
Now this is exactly like the tree we would obtain using the bnb approach:
and now for the sloppy proofs:
- Memoization and bnb tree have the same amount of nodes
- Memoization nodes is dependent of the table size
- Table size is dependent of N and K
- Therefore bnb is not independent of K
- Memoization space is bounded by NK i.e. O(NK)
- Therefore bnb tree complete space (or the space if we do the bnb in a breadth first manner) is always of O(NK) and not O(N^2) because the whole tree is not going to be constructed and it would be exactly like the momization.
- Memoization has better space than the standard dynamic programming.
- bnb has better space than the dynamic programming (even if done in breadth first)
- The simple bnb without relaxation (and just eliminating the infeasible nodes) would have better time than memoization (memoization has to search in the look up table and even if the look up was negligible they would still be the same.)
- If we disregard the look up search of memoization, it is better than dynamic.
- Therefore bnb algorithm is always better than dynamic both in time and space.
Questions:
If by any mean my proofs are correct some questions would arise that are interesting:
- Why bother with dynamic programming? In my experience the best thing you could do in dp knapsack is to have the last two columns and you can improve it further to one column if you fill it bottom to top, and it would have O(K) space but still can't (if the above assertions are correct) beat the bnb approach.
- Can we still say bnb is better if we integrate it with relaxation pruning (with regard to time)?
ps: Sorry for the long long post!
Edit:
Since two of the answers are focused on memoization, I just want to clarify that I'm not focused on this at all! I just used memoization as a technique to prove my assertions. My main focus is Branch and Bound technique vs dynamic programming, here is a complete example of another problem, solved by bnb + relaxation (source: Coursera - Discrete Optimization) :
In practice dynamic programming can be better for integer 0/1 knapsack because: