Documente Academic
Documente Profesional
Documente Cultură
On completion of the Knapsack Problem There are three types of greedy algorithms that can be used,
are :
A. Greedy By Weight
At each step select the object has the lightest weight. Try maximizing the include as many objects to
in a knapsack.
The first thing to do is program sort in ascending objekobjekberdasarkan weightnya. then new
taken one by one object that can be accommodated by knapsack until knapsack
full or object is no longer the can be inserted.
B. Greedy by profit
At each step, select objects has the greatest advantage. Try maximizing the select the object of the most
profitable first.
The first thing to do is program sort descending objects based on profit. Then just taken one by one
object that can be accommodated by knapsack until knapsack full or object is no longer the can be
inserted.
C. Greedy By Density
At every step knapsack filled with objects that have pi / wi the largest, where p is an advantage and w is
heavy goods. Trying to maximize advantage by selecting the object has the greatest density per unit
weight.
The first thing to do is program seeking profit value per weight of each - per unit (density) of each
object. Then the objects were sorted based on its density. then new taken one by one object that can be
accommodated by knapsack until knapsack full or object is no longer thecan be included
Start
True True
sort objects based on the Sort objects based on the
weight of the object in profit of the object in
ascending order descending order
enter objects sequentially into the knapsack without exceeding the maximum
capacity
calculate the total profit by summing the advantages of each object that is inserted
into the knapsack
Finish