2. ๏ก The greedy method is the most straightforward design
technique.
๏ก Most of these problems have โnโ inputs and require us to
obtain a subset that satisfies some constraint.
๏ก Any subset that satisfies these constraints is called A
FEASIBLE SOLUTION.
๏ก A feasible solution that maximizes/minimizes a given
function is called an OPTIMAL SOLUTON.
GENERAL METHOD
3. Algorithm: Greedy(a,n)
// a[1:n] contains n input
{
solution = 0;
for i = 1 to n do
x = select(a);
if Feasible(solution,x) then
soultion = Union(solution,x);
done
return solution;
}
GENERAL ALGORITHM
Selects an input from a[]. The selected
inputโs value is assigned to x.
Is a Boolean valued function that determines
whether x can be included into the solution
vector
Combines x with the
solution and updates
the objective function.
4. KNAPSACK PROBLEM
Knapsack with โmโ
weight
โnโ objects.
W1 , P1
W2 , P2
W3 , P3
W4 , P4
Select from
the given
objects that
will give
MAXIMUM
PROFIT
5. CASE 1 CASE 2
FRACTIONAL KNAPSACK 0 /1 KNAPSACK PROBLEM
If a fraction of an object is selected then it
is termed as โFRACTIONAL KNAPSACK
PROBLEMโ
If the decision is either taking an object
completely or rejecting it completely.
This is termed as, โ0 /1 KNAPSACK
PROBLEMโ
GREEDY APPROACH DYNAMIC PROGRAMMING
SELECTION OF OBJECTS
6. The problem can be stated as follows:-
Maximize 1โค๐โค๐ ๐ ๐ ๐ฅ ๐ โฆโฆโฆ (1)
Subject to 1โค๐โค๐ ๐ค ๐ ๐ฅ ๐ โค ๐ โฆ โฆ . (2)
And 0 โค ๐ฅ ๐ โค 1 , 1 โค ๐ฅ ๐ โค n โฆโฆโฆ (3)
A feasible solution is any set (x1,x2,โฆ.,xn) satisfying
equation (2) and (3).
An optimal solution is a Feasible solution for which
equation (1) is maximized.
PROBLEM STATEMENT