The Knapsack Problem

Problem Description

Given a set of items, each with a weight and a value, determine which items to include in a collection (knapsack) so that the total weight is less than or equal to a given limit and the total value is as large as possible. (Wikipedia)

Pseudo code for a solution can be found on the Wikipedia website.

Note: There are two variations on the knapsack problem. In the 0-1 Knapsack Problem, you must either take an entire item or not. You cannot take half of an item. In the Fractional Knapsack Problem you can take part of an item.

The 0-1 Knapsack Problem

The most common problem is the 0-1 knapsack problem which restricts the number of copies of each kind of item (in the knapsack) to zero or one.

In other words, each item in the list is a single (unique) item. An item is either in or out of the knapsack. (Part of an item can not be in the knapsack; Only the whole thing.)

Project #1

Find the 0-1 knapsack problem solution using the following data given a maximum weight of 67 lbs.

Calculate and display the optimal solution

Problem from Wikipedia page
ItemWeight (lbs)Value
123505
226352
320458
418220
532354
627414
729498
826545
930473
1027543

Project #2

Create an interactive program that allows the user to create their own 0-1 knapsack problem.

Include a name or number for each item? (This may make it easier to read and understand the list when displayed.)

Use a simple menu to start. Can you convert the program to a GUI?

Links

0/1 Knapsack Problem