dave risch. project specifications there is a “knapsack” that you want to fill with the most...
TRANSCRIPT
The Knapsack ProblemDave Risch
Project SpecificationsThere is a “knapsack” that you want to fill with the
most valuable items that are available to you.Each item has a value, weight, and value density.
(which is determined by dividing the value/weight)The items then get listed in order of value density.Uses a greedy algorithm to select the highest
valued items.Keeps selecting items until the weight of the next
best item can’t fit.At that point, it will skip that item and look for the
next item that can fit.
GoalsCreate a NP-hard program that uses a greedy
algorithmProgram will choose the best items for you to
take within a certain weight capacity.Output the items, along with their values,
weights and value densities.
ApplicationsApplications that use a greedy algorithm
usually fail to find the optimal solution.Yet when they do work for a certain class,
they are generally used because of their speed.
Greedy algorithms are used in applications such as Kruskal’s, Prim’s, and Dijkstra’s.
Also used in routing. A message is forwarded to the closest neighboring node.
DesignUse object programming to make items with value,
weights and value densities.Put objects in an array, and sort objects in order of
their densities.Loop through, choosing the highest value density
objects.Add weights until the next item won’t fit the weight
restriction.Skip that object and check the object after to see if it
will fit and so on until the weight is maxed out. Add selected items to a list, output the item, value,
weight and value density.
TestingTo test the program, I will use different
values, weights, value densities to see if it chooses the correct items.
Use different weight restrictions to see if it will choose an item even though the item before it exceeded the max weight.
Add or remove items that you can take to mix things up.
Conclusions so farAfter further researching, I found you can
use dynamic programming to make the knapsack problem more efficient than if you use a greedy algorithm.