Unformatted text preview: CS 570 HW3 Solution Problem 3 Proof. (by contradiction) Assume greedy is not optimal, and let’s see what happens. Let W1, W2, W3, … WK denote the amount of each loaded boxes by greedy as follows.
w1 w2 w3 w4 w5 w6 w7 ... W1 W2 Wk Let W’1, W’2, W’3, … W’p denote the amount of each loaded boxes by so called an “optimum” solution as follows.
w1 w2 w3 w4 w5 w6 w7 ... W’1 W’2 W’p Let’s assume that W1=W’2, W2=W’2 … Wr=W’r (up to r), but, for r+1, the loading amounts become different for the first time. Then, Wr+1 W’r+
1 Wr+1 Wr+2 Case 1 W’r+
1 Case 2 Case 3 Now, we can think of 3 cases as above. Case 1. This case is impossible in reality since it is larger than Wr+2. Case 2. This is the best possible case for the suggested method. Case 3. This is feasible also. So, we conclude that the suggested approach requires same number or more number of trucks than that of greedy approach. (At best, the algorithm can work same as greedy algorithm.) <Contradiction> So, greedy is the best we can do for the truck company. <End of Proof> 3. Construct a minheap of the sublists, each sublist is a node in the heap. When comparing two sublists, compare the first element, which is the minimum in the sorted sublists, the sublist with smaller first element is considered smaller. This will cost O(k). The in the ExtractMin algorithm, every time we remove the first element in the root sublist, and adjust the heap according the the new first element of the root sublist, if it has no elements left, move the last sublist to the root position and adjust the heap. It costs O(lg k) to adjust the heap because the number of nodes in the heap is k, to get the full sorted list, we need to extract n elements in total, each results in an adjust of the heap, so the total running time is O(n lg k + k), which is O(n lg k). ...
View
Full Document
 Fall '06
 Shamsian
 Algorithms, Greedy algorithm, 2 w, 1 W

Click to edit the document details