{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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 ﬁrst integer such that w 1 + w 2 + ··· + w k +1 > L . To show that this is optimal, we ﬁrst 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 ﬁrst 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
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

{[ snackBarMessage ]}

Ask a homework question - tutors are online