The goal is to maximize the value stored in the knapsack without going over the weight limit. The “0/1” part means that you can only take entire items.
It can be solved using Greedy Algorithms though it’s not the optimal solution for it. it solves by iteratively adding value-to-weight ratio to the knapsack until the knapsack is full or no more items can be added.
Here is a step-by-step description of the Greedy Algorithms for the knapsack problem:
- Sort the items in decreasing order of value-to-weight ratio.
- Iterate over the items in sorted order.
- If the item can fit into the knapsack, add it to the knapsack.
- If the item cannot fit into the knapsack, skip it.
- Repeat steps 3 and 4 until the knapsack is full or no more items can be added.