Knapsack Problem


Knapsack Weight (KG)

Item 1 Profit 1

Result


Problem Description


This 0/1 Knapsack Problem uses Greedy algorithm/method. Greedy algorithm will always take the items which maximized the profit of the knapsack. 0/1 Knapsack either takes the item as a whole or leave it and not take it. the algorithm chooses the items acording to the highest to the lowest profit by weight (profit/weight) of each item.


The limitation of knapsack greedy which will not give the optimal solution but will give the profit which is maximized.


For Example:

Knapsack Weight: 50 KG

Item 1: 10KG Profit : 60

Item 2: 20KG Profit : 100

Item 3: 30KG Profit : 120

Output: (1,1,0)


The output will not be (0,1,1) because if we calculate the profit by weight of this output it will be (220/50 = 4.4). Whereas if we take the profit by weight of the output (1,1,0) it is (160/30 = 5.3333) which is higher that the other one. therefore the profit is maximized when we take item 1 and item 2.


Decimal to Binary Converter