0% found this document useful (0 votes)
3 views9 pages

67ecdf0678e19_ppt

The document discusses the Knapsack Problem, specifically the Fractional Knapsack Problem, which involves maximizing profit by selecting items with given weights and values within a limited capacity. It outlines a greedy algorithm approach to solve the problem, emphasizing the importance of the value-to-weight ratio for optimal selection. An example is provided to illustrate the algorithm's application in determining the optimal fractions of items to include in the knapsack.

Uploaded by

tsumith9876
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

67ecdf0678e19_ppt

The document discusses the Knapsack Problem, specifically the Fractional Knapsack Problem, which involves maximizing profit by selecting items with given weights and values within a limited capacity. It outlines a greedy algorithm approach to solve the problem, emphasizing the importance of the value-to-weight ratio for optimal selection. An example is provided to illustrate the algorithm's application in determining the optimal fractions of items to include in the knapsack.

Uploaded by

tsumith9876
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

DESIGN AND ANALYSIS OF ALGORITHMS

Topic Title – KNAPSACK PROBLEM

Presenter’s Name – Dr. M. Purushotham Reddy


Presenter’s ID – IARE10669
Department Name – Information Technology

1
KNAPSACK PROBLEM
KNAPSACK PROBLEM

For example consider the Fractional Knapsack Problem. The


local optimal strategy is to choose the item that has maximum
value vs weight ratio. This strategy also leads to global optimal
solution because we allowed to take fractions of an item
KNAPSACK PROBLEM

Knapsack Problem:
•A knapsack (kind of shoulder bag) with limited weight capacity.
•Few items each having some weight and value.
•The value or profit obtained by putting the items into the
knapsack is maximum.
•And the weight limit of the knapsack does not exceed.
KNAPSACK PROBLEM

knapsack Problem: Let us apply the greedy method to solve the


knapsack problem. We are given ‘n’ objects and a knapsack. The
object ‘i’ has a weight Wi and the knapsack has a capacity ‘m’. If
a fraction xi, 0 < xi < 1 of object i is placed into the knapsack then
a profit of pi xi is earned. The objective is to fill the knapsack that
maximizes the total profit earned.
Maximize

subject to where, 0 < xi < 1 and 1 < i < n

Since the knapsack capacity is ‘m’, we require the total weight of


all chosen objects to be at most ‘m’. The problem is stated as:
The profits and weights are positive numbers
KNAPSACK PROBLEM

If the objects are already been sorted into non-increasing order of p[i] / w[i]
then the algorithm given below obtains solutions .
Algorithm GreedyKnapsack (m, n)
// P[1 : n] and w[1 : n] contain the profits and weights respectively of
// Objects ordered so that p[i] / w[i] > p[i + 1] / w[i + 1].
// m is the knapsack size and x[1: n] is the solution vector.
{
for i  1 to n do x[i]  0.0 // initialize x
U  m;
for i  1 to n do
{
if (w(i) > U) then break;
x [i]  1.0; U  U – w[i];
}
if (i < n) then x[i]  U / w[i];}
KNAPSACK PROBLEM
Consider the following instance of the knapsack problem: n = 3, m = 20,
(p1, p2, p3) = (25, 24, 15) and (w1, w2, w3) = (18, 15, 10).
1. First, we try to fill the knapsack by selecting the objects in some order

x1 x2 x3  wi xi  pi x i

1/2 1/3 1/4 18 x 1/2 + 15 x 1/3 + 25 x 1/2 + 24 x 1/3 +


10 x 1/4 = 16.5 15 x 1/4 = 24.25

2.Select the object with the maximum profit first (p = 25). So, x 1 = 1 and profit earned is
25. Now, only 2 units of space is left, select the object with next largest profit (p = 24).
So, x2 = 2/15

x1 x2 x3  w i xi  pi xi x

1 2/15 0 18 x 1 + 15 x 25 x 1 + 24 x 1
2/15 = 20 2/15 = 28.2
Example: Number of items n=3, Capacity m=45 &the weight :

Now find out the fraction of chosen items with maximum p

 Find the unit ui using the formula ui=pi/wi.


 Find the fraction of the items xi that will be taken in order
to get maximum profit.
Thank You

You might also like