Professional Documents
Culture Documents
Module 2 Activity#1 Greedy Algorithm Programming
Module 2 Activity#1 Greedy Algorithm Programming
Part 1:
Step 2:
Step 3:
Step 4:
Step 5:
The greedy chosen on Value has the lower food selected because it only finds the largest value within the
list of objects and does try to put all large values on the knapsack, its full not maximizing the number of
items that is able to be put in the knapsack while greedy by cost and density contains the same items
taken from the difference greedy by density does values outputted in descending order meaning the
algorithm is maximizing the total values it can carry in the knapsack. In conclusion the winner in the
greedy by density for it searches the items efficiently maximizing all the possibilities.
In conclusion of part 2, by greedy summing the value and density it has the same total value of items
taken. Greedy by value has a high constraint because greedy value would pick all the items starting from
highest to lowest value and put it all in the knapsack until it reaches the limit. A reason why the bigger
constraint the more items it will put in the knapsack but of course this depends on the values of the items.
The greedy by cost has the lowest total value of items taken for this is because this starts from the lowest
to highest values and try to put it all in the knapsack same as the greedy by value for they are both not
maximizing all the possibilities they are putting the items base on one choice only in this case they are
only picking items to put in the knapsack based on either value or cost. While the greedy by density is
maximizing all the possibilities from the items cost and calories it efficiently picks what to put in the
knapsack that’s a reason for greedy by density wins this portion.