Successfully reported this slideshow.
Upcoming SlideShare
×

# Knapsack algoritm

24 views

Published on

this slide is made on knapsack algorithm in fractional method.

Published in: Education
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

### Knapsack algoritm

1. 1. Hello Everyone.
2. 2. PRITAM GOLDER ID: 172-15-9879
3. 3. What is it ?
4. 4. Bag???What is it ?
5. 5. Bag??? No, It’s a Knapsack. What is it ?
6. 6. Value: 25 Value: 40 Value: 50 Value: 15Value: 20 Weight: 4 Weight: 1Weight: 2 Weight: 3 Weight: 5Space: 6(weight) Value: ???? Get the Maximum Value: store
7. 7. Get the Maximum Value: Now, We are facing a big problem. There are many options to get the maximum value. This problem is called knapsack problem. Good thing is. There is an algorithm to solve this. Today, we are going to learn this
8. 8. Solve Knapsack Problem: • Firstly, create a table store the data. Item 1 2 3 4 5 Value 25 20 15 40 50 Weight 3 2 1 4 5 • Secondly, get the ratio value/weight. Item 1 2 3 4 5 Value 25 20 15 40 50 Weight 3 2 1 4 5 Value/weight 8.3 10 15 10 10
9. 9. Solve Knapsack Problem: Item 1 2 3 4 5 Value 25 20 15 40 50 Weight 3 2 1 4 5 Value/weight 8.3 10 15 10 10 • Now, sort the values on the basis of ratio. Item 3 2 4 5 1 Value 15 20 40 50 25 Weight 1 2 4 5 3 Value/weight 15 10 10 10 8.3 Sort
10. 10. Solve Knapsack Problem: • Now, We have to keep taking items till the knapsack filled up. Item 3 2 4 5 1 Value 15 20 40 50 25 Weight 1 2 4 5 3 Value/weight 15 10 10 10 8.3 Item Weight Value Space remaining 3 1 15 5 2 2 20 3 4 3 30 0 Fractional Total value: 65
11. 11. Code of Knapsack Algorithm
12. 12. Run Knapsack Algorithm
13. 13. That’s All. Thank you.