There are two well-known knapsack problems:
1) Given n
items, each has its weight
and cost
. We need to select items, that will fit in our knapsack and have maximal cost in sum. It can be easily solved using dynamic programming
.
2) Fractional knapsack: same as the first, but we can take not the whole item only, but its part. This problem can be easily solved with greedy algorithm
.
Imagine we are using greedy algorithm
from second problem to solve the first one. How can I prove, that the solution we will get is no more than two times worse, than the optimal one?