Loading topic
[60, 100, 120], weights [10, 20, 30], capacity 50.5 min readsorted with a key, you know Big-O notation, and you know the knapsack problem statement from the first chapter. In the fractional variant you may take any fraction of an item, between 0 and 1. Taking a fraction gives you the same fracti5 min readbest(i, c) is the highest value you can get from items i through n - 1 with remaining capacity c:5 min readdp[i][c] holds the best value you can get using the first i items with capacity c, and it is filled by the 0/1 recurrence:5 min readknapsack_01_1d. It explains why the O(nW) algorithm counts as "pseudo-polynomial" rather than polynomial. It also explains why that label fits with the 0/1 knapsack problem being N5 min readdp[t] holds the minimum weight needed to reach a total value of exactly t. It also assumes you can reconstruct chosen items from a 2D table and that you know why 0/1 knapsack is NP-hard.6 min read