Fractional Knapsack Problem | DAA
Fractional Knapsack Problem
Here we arrange the items by ratio vi/wi.
Algorithm
for the above algorithm is O(n). However our requirement is that v[1 ... n] and w[1 ... n] are sorted,
I = {I1, I2, I3, I4, I5}
w = {5, 10, 20, 30, 40}
v = {30, 20, 100, 90, 160}
The knapsack has a capacity of W=60, then find optimal profit earned by using a fractional knapsack.
Items |
Wi |
Vi |
I1 |
5 |
30 |
I2 |
10 |
20 |
I3 |
20 |
100 |
I4 |
30 |
90 |
I5 |
40 |
160 |
Items |
Wi |
Vi |
Pi=vi/wi |
I1 |
5 |
30 |
6.0 |
I2 |
10 |
20 |
2.0 |
I3 |
20 |
100 |
5.0 |
I4 |
30 |
90 |
3.0 |
I5 |
40 |
160 |
4.0 |
Items |
Wi |
Vi |
Pi=vi/wi |
I1 |
5 |
30 |
6.0 |
I3 |
20 |
100 |
5.0 |
I5 |
40 |
160 |
4.0 |
I4 |
30 |
90 |
3.0 |
I2 |
10 |
20 |
2.0 |
Comments
Post a Comment
Subscribe Us and Thanks for visiting blog.