You are on page 1of 8

Greedy Algorithms

A greedy algorithm is an approach


problem the
for solving a
by selecting
best option available at the moment

At doesn't whether the current


worry
lost result will bring the overall
optimal result

The algorithms never reverses the earlier


decisions the choice is
It works
even
ifadown approach
wrong
in top
his algorithm not the
may all produce Its
lost result for problems
because it always goes the local
for
best choice to produce the global
lust result

However determine
we can
if the
algorithm can be used with
any
the problem has the
problem if
for if for
following properties

Greedy Choice Property If


an optimal
solution to the problem can be found
by choosing the lost choice at each
step without reconsidering the pamion
steps once choosen the problem can
be solved using a greedy approach
This property is called greedy choice
property
a
Optimal Substructure If the optimal
overall solution to the problem
corresponds to the optimal solution to
its saleproblems then the problem
can be solved using a greedy
approach This property is called optimal
substructure

Advantages of Greedy Approach

The algorithm is
easy to describe
g easy
This algorithm perform better than
can
other algorithms duet not in all cases

Drawback of Greedy Algorithms

Dont always produce the optimal


solution

20

2
31

7 10
P A B

I
si
Iidontainhigh
sa s
fusibl5T
Here we have to complete the journey
B 12 Hrs with multiple
from A in
solutions

The constraint here is 12has time limit


somehow we can only cover Itis
distance using a train or car

For a problem there are many sat


but the sot satisfying the constraint
are called Feasible Solution

want to
If we
finish the journey in
minimum cost then it becomes a
minimizationproblem
Out of the two sol the train has
minimum cost will be the optimal sat

An optimal solution which already is a

feasible sol with minimum cost or the


lost result

For any problem there can be only


one optimal solution

If a prolelem requires a minimum result


on maximum result is called an optimize
lion problem

Greedy methods is required to solve


optimization problems

I Greedy Method

a
Dynamic Programming

3 Branch and Bound


The above the ways to solve the
are

optimization problems

GREEDYMETHI
a
Algorithm Greedy
affiant
i ton do
for E se select Ca

then
ifsolution
feasible x

solution tx

The above is the general method of Greedy


Algorithm

KNAPSACK

PROBLEM
IROBLEM
objects O 1 2 3 4 5 6 7

P 10 5 15 7 6 18 3
Profits

2 3 5 7 I 4 I
Weight w
516316 4.53
n
m 15

The no objects here are 7 and the


of
capacity of knapsack is 15
carrying
the
The
profit here is
gain we
get
these objects
after transferring
one to another
from
place

Here we assume we can take fractions


also Cie items are divisible

C
where O E KEI
Here we decided that we use the
Profit weight so we can calculate the
Profit per kg of every element

xltlx4tl
12tzx31xsjg.tt

1x10tystyygthtertts
Exipi

Constraint Exiwism
Objective ma Zai p

You might also like