sol9 - n miles out of Newark. Suppose station j is the...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CIS 435, Fall 2000, Jim Calvin Homework #9 Solutions 17.2-3. Suppose we have n items with weights w 1 w 2 ≤ ··· ≤ w n and values v 1 v 2 ≥ ··· ≥ v n . The optimal algorithm is: take items 1 , 2 , . . . , k where k is the first integer such that w 1 + w 2 + ··· + w k +1 > L . To show that this is optimal, we first show that an optimal solution contains item 1 (assuming that L > w 1 ). If not, replace any chosen item with 1 and the weight is no greater and the value is at least as high. Thus there is an optimal solution containing item 1. An optimal solution to the subproblem with items 2 through n must contain item 2, and so on. 17.2-4. Prof. Midas should drive as far as he can on each tank of gas without running out between stations. Since after the first gas stop the remaining problem is of the same form as the original, it is enough to prove than an optimal solution has him stopping at the furthest gas station less than
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n miles out of Newark. Suppose station j is the furthest from Newark less than n miles away, and that an optimal solution has him stopping at stations i 1 , i 2 , . . . , i k , where i 1 < j . Then replacing i 1 with j is still feasible, and results in the same number of stops, so is also optimal. 24.2-2. Let A = ( a ( u, v )) be the “adjacency matrix”, where a ( u, v ) = w ( u, v ). Prim(A,w,r) S ← { r } , T ← ∅ for each v ∈ V- { r } do nearest [ v ] ← r while S 6 = V do min ← + ∞ for each v ∈ V-S do if a ( v, nearest [ v ]) < min then do min ← a ( v, nearest [ v ]) next ← v S ← S ∪ { next } T ← T ∪ { ( next, nearest [ next ]) } for each v ∈ V-S do if a ( v, nearest [ v ]) > a ( v, next ) then nearest [ v ] ← next 24.2-6. Find the minimum spanning tree; it has the least maximum edge weight. 1...
View Full Document

This note was uploaded on 09/29/2010 for the course CS CS 435 taught by Professor Alex during the Spring '09 term at NJIT.

Ask a homework question - tutors are online