Knapsack Problem - Group 6

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Group members & Matricules

1. Britney Berinyu Moukoko A. ICTU20233901


2. Penchia Ornelle ICTU20234123
3. Precious Asher ICTU20233744
4. Nkiyam Praises ICTU20233776
5. Precious Maloba ICTU20233724
6. Sirri Queen ICTU20233811

Algorithm and Data structures II -


THE KNAPSACK PROBLEM

Table of contents:
1. What is a knapsack problem?
2. Types of knapsack problems
3. Differences between 0/1 knapsack problem and the fractional
knapsack problem.
4. Differences between the bounded and unbounded knapsack problem.
5. Differences between the 0/1 knapsack problem wrt bounded and
unbounded knapsack problems.
6. Advantages and disadvantages of using the knapsack problem.
7. Applications of the knapsack problem in real life.
_____________________________________________________

1. What is the knapsack problem?


The knapsack problem is a combinatorial optimization problem meaning that
it entails finding an optimal object from a set of given objects. It can be
defined using the problem statement below:
Given a knapsack of maximum capacity W, and arrays of given items of
weights w_i and corresponding values v_i , where i ={0,1,2,3…}, we have to
have to fill the knapsack such that the total weight we put in the knapsack will
be less than or equal to the maximum capacity and the total value will be
maximised.
2. Types of Knapsack problem
There are 4 types of knapsack problems:
2.1. 0/1 knapsack problem
2.2. Fractional knapsack problem
2.3. Bounded knapsack problem
2.4. Unbounded knapsack problem

2.1. 0/1 knapsack problem


Given an array of items of weights w_i and values v_i respectively and a known
maximum capacity W of a bag, the knapsack problem entails filling the bag
such that the total weight is less than or equal to W and the total value is
maximised. Here, we can only decide to choose a whole item or not choose it
at all hence we use the dynamic programming approach for this case.
Example:

Start filling the table row wise top to bottom from left to right using the formula:

After using the formula to fill the table, we have;

The last entry represents the maximum


possible value that can be put into the knapsack which is 7. We mark the rows
labelled “1” and “2” to show that their items will be put in the knapsack to obtain a
maximum value.
2.2. Fractional knapsack problem
Given an array of items of weights w_i and values v_i respectively and a known
maximum capacity W of a bag, this knapsack problem entails filling the bag
such that the total weight is less than or equal to W and the total value is
maximised. Here, we can break a whole item hence we can use the greedy
approach for this case.
Example:
arr[v,w] = {{60, 10}, {100, 20}, {120, 30}}, W = 50
By taking items of weight 10 and 20 kg and 2/3 fraction of 30 kg.
Hence total value will be 60+100+(2/3)(120) = 240

2.3. Unbounded knapsack problem


Given an array of items of weights w_i and values v_i respectively and a known
maximum capacity W of a bag, this knapsack problem entails finding the item
with the highest value to weight ratio and filling the bag with this item such that
the total weight is less than or equal to W and the total value is maximised.
Here, we can put in the same item more than once hence we can use the
greedy approach for this case.
Example:
val[] = {100, 60, 120}, wt[] = {20, 10, 30}, W = 50
The ratios will be in the order 6,5,4 from (60/10 ,100/20 and 120/30)
respectively.
Hence the answer is 300
2.4. Bounded knapsack problem
Given an array of items of weights w_i and values v_i respectively and a known
maximum capacity W of a bag, this knapsack problem entails finding the item
with the highest value to weight ratio and filling the bag with this item such that
the total weight is less than W and the total value is maximised. Here, there is a
limit to the number of times the same item can be put, hence we can use the
greedy approach for this case.

3. Key differences between Fractional and 0/1 knapsack


problems
Fractional knapsack 0/1 knapsack problem
It is solved using the greedy approach It is solved using the dynamic
programming approach

Breaking of items in order to You can only choose a whole item


maximise value is allowed

4. Key differences between bounded and unbounded


knapsack problems

Unbounded knapsack Bounded knapsack


An item can be selected many An item has a limit to the number
times without limit as long as total of times it can be selected
weight < maximum capacity

5. Differences between the 0/1 knapsack problem wrt


bounded and unbounded knapsack problems.
0/1 knapsack problem Bounded and unbounded
knapsack problems
It is used using the dynamic It is solved using the greedy approach
programming approach

An item can be used only once There can be more than one instance
of an item.

6. Advantages and disadvantages of Knapsack problems


Advantages
a. One of the main benefits is its simplicity in understanding and
implementation.
b. The knapsack problem often provides an optimal solution, implying
that it's impossible to find a better solution than this.
c. Also, the fractional knapsack problem is highly efficient, meaning it
can be solved relatively quickly.

Disadvantages

a. The knapsack problem is sensitive to the input data, that is, small
changes in the input values can result in significantly different solutions.

7. Applications of knapsack problem in daily life


1. In logistics, it helps in determining the most efficient way to load a ship with
a given set of items.
2. In the field of finance, it aids in choosing the best investments to maximise
returns within a budget.
3. One of the early applications of the Knapsack problem was in construction
and scoring of exams in which the test takers have a choice as to which
questions they answer.

You might also like