230 likes | 279 Views
This presentation on knapsack Problem Using Dynamic Programming will acquaint you with a clear understanding of the fractional or 0-1 knapsack problem statement and solution implementation. In this Data Structure Tutorial, you will understand why the difference between 0-1 knapsack and fractional knapsack problems and how you can solve the same problem with less time complexity using DP. Finally, we will cover the dynamic programming implementation of both Knapsack problems. <br>
E N D
Agenda What is Knapsack Problem
Agenda 0-1 Knapsack Problem
Agenda Implementation
Agenda Fractional Knapsack Problem
Agenda Implementation
What is Knapsack Problem? The knapsack problem is a problem that is used to demonstrate both the problem and the solution. It gets its name from a situation in which the amount of goods that can be carried in a fixed-size knapsack is limited. Given a set of goods with certain weights and values, the goal is to stuff as much value as possible into the knapsack while staying within the weight limit.
0-1 Knapsack Problem 6Kg 10Kg 3Kg 3Kg 2Kg 2Kg 2Kg We will be given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack.
0-1 Knapsack Problem 10Kg 3Kg 3Kg 2Kg 6Kg 2Kg 2Kg We are supposed to fill this knapsack, but we can’t break the item.
0-1 Knapsack Problem 10Kg 3Kg 2Kg 6Kg 2Kg 2Kg 3Kg We must either pick the entire item or not pick at all.
0-1 Knapsack Problem 10Kg 3Kg 2Kg 6Kg 2Kg 2Kg 3Kg Sometimes it may even lead to a knapsack with some spare space left with it.
Fractional Knapsack Problem 6Kg 10Kg 3Kg 3Kg 2Kg 2Kg 2Kg We will be given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack.
Fractional Knapsack Problem 10Kg 3Kg 3Kg 2Kg 1Kg 2Kg 6Kg 2Kg 2Kg Unlike 0-1 knapsack problem, we can break items to maximize the total value of knapsack.
Fractional Knapsack Problem 10Kg 3Kg 1Kg 2Kg 2Kg 6Kg 2Kg 2Kg 3Kg Here we will break this 3kg item into a 2kg and 1kg item to completely fill the knapsack
Fractional Knapsack Problem 10Kg 2Kg 1Kg 2Kg 6Kg 2Kg 2Kg 3Kg Here we will break this 3kg item into a 2kg and 1kg item to completely fill the knapsack