sol1 - Introduction to Algorithms Solution Set 1 CS 4820,...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: Introduction to Algorithms Solution Set 1 CS 4820, Spring 2010 (1) The algorithm restores the websites in decreasing order of c i /t i , where c i is the rate of lost dollars per hour for site i , and t i is the number of hours to finish the job. Analysis of running time. Computing the ratio for each job requires O ( n ) time, and sorting them requires O ( n log n ) time. Correctness. The proof of correctness uses an exchange argument, similar to the proof of correctness of the scheduling algorithm in Section 4.2 of Kleinberg & Tardos. If you have a schedule with two consecutive jobs i,j (in that order) and you swap the order of i and j , the net change can be broken down as follows. Site i is restored t j hours later, which increases the lost revenue by c i t j . Site j is restored t i hours earlier, which decreases the lost revenue by c j t i . All other sites are restored at the same time. Thus the net change in lost revenue is c i t j- c j t i = c i t i- c j t j ! t i t j . (1) This implies the following facts. 1. In any optimal schedule, there cant be two consecutive jobs i,j such that ( c i /t i )- ( c j /t j ) is negative. If there were, one could decrease the lost revenue by swapping the order of i and j . 2. Therefore, in every optimal schedule, the jobs are sorted in order of decreasing c i /t i . 3. Swapping the order of two consecutive jobs i,j such that c i /t i = c j /t j has no effect on the amount of lost revenue. 4. Therefore, for every ordering of the jobs such that the ratios c i /t i form a non-increasing sequence, the cost is equal to that of an optimal schedule. (2) The algorithm initializes a set of events denoted by their occurrence times x i ( i = 1 ,...,n ), and a set S of intervals denoted by their left endpoints t i- e i and right endpoints t i + e i ( i = 1 ,...,n ). As usual, we say that an interval with endpoints a,b contains an event x if it is the case that a x b . The events are sorted in increasing order of occurrence time, and they are processed one by one in that order. When each event x i is processed, the algorithm identifies all of the intervals in S that contain x i . If no interval in S contains x i , then the algorithm terminates and declares that no association exists. Otherwise, among all the intervals in S that contain x i , it selects the one whose right endpoint t j + e j is earliest. It associates x i with t j , removes the interval ( t j- e j ,t j + e j ) from the set S , and continues processing the next event in the list. If it reaches the end of the list of events and finds that it has associated each one with a timestamp...
View Full Document

Page1 / 4

sol1 - Introduction to Algorithms Solution Set 1 CS 4820,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online