Knapsack Problem, Dynamic Programming Approach - Design and Analysis - Study Notes, Study notes of Digital Systems Design

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

2011/2012

Uploaded on 11/03/2012

ankitay
ankitay 🇮🇳

4.4

(50)

106 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture No. 21
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 Θ(n3).
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:
6.5 0/1 Knapsack Problem
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?
Docsity.com
pf3

Partial preview of the text

Download Knapsack Problem, Dynamic Programming Approach - Design and Analysis - Study Notes and more Study notes Digital Systems Design in PDF only on Docsity!

Lecture No. 21

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:

6.5 0/1 Knapsack Problem

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:

  • Since there are n items, there are 2 n^ possible combinations of the items (an item either chosen or not).
  • We go through all combinations and find the one with the most total value and with total weight less or equal to W.

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:

  1. Simple Subproblems : We should be able to break the original problem to smaller Subproblems that have the same structure
  2. Principle of Optimality : Recursively define the value of an optimal solution. Express the solution of the original problem in terms of optimal solutions for smaller problems.
  3. Bottom-up computation : Compute the value of an optimal solution in a bottom-up fashion by using a table structure.