This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS 577: Introduction to Algorithms 10/17/06 Homework Solution: 3a Instructor: Shuchi Chawla TA: Siddharth Barman Question 1 The dynamic program is to fill an n V matrix M iteratively. Here M ( i,j ) = w implies that using objects from the { 1 , 2 ,...,i } we can fill up the knapsack providing value j and consuming weight no less than w . Let w i represent the weight (size) of object i and v i represent its value, we have the recurrence relation for filling up M as follows: M ( i,j ) = min( M ( i 1 ,j ) ,M ( i 1 ,j v i ) + w i ). If at any point this min value is greater than W the capacity of the knapsack we set M ( i,j ) = indicating its infeasibility. Note that as a convention ( i,j ) configurations which are not possible are represented by setting M ( i,j ) = . The algorithm is to first initialize M (1 ,v 1 ) = w 1 and for j 6 = v 1 we set M (1 ,j ) = . Next we scan the matrix from row numbered 2 to n , filling up the matrix using the recurrence relation maintaining M ( i,j ) < W at every step. The final output is the maximum value j for which M ( n,j ) < . The exact set can be obtained by tracing back the optimal path in the matrix. The correctness of the proposed algorithm follows inductively from the recurrence relation. The base case of a single object holds as a single object can provide a value of v 1 and consume weight equal to w 1 and we set M (1 ,v 1 ) = w 1 . Next assuming that we have optimal solutions for all values....
View
Full
Document
 Spring '08
 JOSEPH
 Algorithms

Click to edit the document details