

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Knapsack Problem, Simple Subproblems, Principle of Optimality, Bottom up computation, Construction of optimal solution, Knapsack Problem Dynamic Programming Approach are the key points in this study notes file.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Here is the dynamic programming based algorithm for computing the minimum cost of chain matrix multiplication.
Analysis: There are three nested loops. Each loop executes a maximum n times. Total time is thus Θ(n 3 ). The s matrix stores the values k. The s matrix can be used to extracting the order in which matrices are to be multiplied. Here is the algorithm that caries out the matrix multiplication to compute Ai..j:
A thief goes into a jewelry store to steal jewelry items. He has a knapsack (a bag) that he would like to fill up. The bag has a limit on the total weight of the objects placed in it. If the total weight exceeds the limit, the bag would tear open. The value of of the jewelry items varies for cheap to expensive. The thief’s goal is to put items in the bag such that the value of the items is maximized and the weight of the items does not exceed the weight limit of the bag. Another limitation is that an item can either be put in the bag or not - fractional items are not allowed. The problem is: what jewelry should the thief choose that satisfy the constraints?
Formally, the problem can be stated as follows: Given a knapsack with maximum capacity W, and a set S consisting of n items Each item i has some weight wi and value value vi (all wi , vi and W are integer values) How to pack the knapsack to achieve maximum total value of packed items? For example, consider the following scenario:
Figure 6.3: Knapsack can hold W = 20
The knapsack problem belongs to the domain of optimization problems. Mathematically, the problem is
The problem is called a “0-1” problem, because each item must be entirely accepted or rejected. How do we solve the problem. We could try the brute-force solution:
Clearly, the running time of such a brute-force algorithm will be O(2n ). Can we do better? The answer is “yes”, with an algorithm based on dynamic programming Let us recap the steps in the dynamic programming strategy: