HW3_solution - CS 570 HW3 Solution Problem 3 Proof(by...

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

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 min-heap 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 Extract-Min 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

{[ snackBarMessage ]}

Ask a homework question - tutors are online