preview

Examples Of 0-1 Knapsack Problem

Decent Essays

CHAPTER 2
0-1 KNAPSCAK PROBLEM
2.1 The 0-1 Knapsack Problem (KP)
The Knapsack Problem is a combinatorial optimization problem, which search out a best solution from among many other feasible solutions. It is concerned with a fixed size knapsack that has positive integer capacity (or volume) C. There are n numbers of distinct items that may potentially be placed in the knapsack. Item i has a positive integer capacity Ci and integer benefit Bi. In addition, there is Ki quantity of item i available, where quantity Ki is an integer with positive value satisfying 1 ≤ Ki ≤∞.
Let Xi determines how much quantity of item i are to be filled into the knapsack. The aim is to:
Maximize
N
∑ Bi Xi i = 1

Subject to the constraints
N
∑ Ci Xi ≤C i = 1

And …show more content…

It is only used in small instances of 0-1 knapsack problem.
2.2.2 Dynamic Programming
Dynamic Programming is an algorithm paradigm for solving optimization problems that broke the problem into sub problems. Each of the sub-problems solves only once and results are stored in a table rather than solving again and again. Then the table is used to retrieve the solution of original problem. The dynamic programming is based on bottom-up approach.
To design the code of the 0/1 Knapsack problem using dynamic programming algorithm, first requirement is to a recurrence relation that represents a solution to an instance of the knapsack problem.

ALGORITHM: Dynamic Programming
Values (stored in array v)
Weights (stored in array w)
Number of distinct items …show more content…

However, it needed more memory because recursive called to demand additional memory. Overall memory function is more efficient than dynamic programing.
2.2.4 Greedy Algorithm
Greedy programing is a mathematical technique that is based on the recursive creation of an object for every possible unit. Recursion is a process in which a particular solution is depends upon results that are coming out from the smaller units of same problem. The benefit of greedy algorithms is that it is straightforward and easy but it is used for short term solution only.
Some Greedy strategies to solve the 0/1 Knapsack problem:
1. Select the item which has the maximum value than other item this expand the knapsack value as speedily.
2. Select the lightest item and remove it from knapsack that allowing more items to be filled in the knapsack.
3. Select the items which have a high value per weight as possible.

By all these three strategies. We got the optimal solution with the third strategy -high value-to-weight ratios of items.

ALGORITHM GreedyAlgorithm (Weights [1 … N], Values [1 …

Get Access