This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Computer Science C73 October 3, 2007 Scarborough Campus University of Toronto Solutions for Homework Assignment #1 Answer to Question 1. Intuitively, to minimize total waiting time, we want long lobs to appear as late as possible. This is because a job delays all subsequent jobs; so, a long job that appears early penalises many jobs by a lot. We now make this intuition more rigorous. An inversion of schedule s is a pair of jobs ( i,j ) such that s ( i ) &lt; s ( j ) but t ( i ) &gt; t ( j ) (i.e., in schedule s , a longer job i appears before a shorter job j ). Claim. If s is optimal, it has no inversions. Proof. We prove the contrapositive: Let ( i ,j ) be an inversion of s ; we will prove that s is not optimal. First observe that there is also an inversion ( i,j ) such that i appears immediately before j in s . (To see why, consider the sequence of jobs from i to j in the order in which they appear in s . The corresponding sequence of durations of these jobs cannot be nondecreasing, since t ( i ) &gt; t ( j ). Therefore there are two consecutive jobs i and j in this sequence such that t ( i ) &gt; t ( j ).) Consider now the schedule s obtained from s by switching the order of the consecutive jobs i and j . Let WT ( s ) and WT ( s ) denote the total waiting times of s and s . Note that in s , the waiting time of every job other than i and j is the same as in s ; the waiting time of i has been increased by t ( j ); and the waiting time of j has been reduced by t ( i ). Therefore, WT ( s ) = WT ( s ) + t ( j ) t ( i ) &lt; WT ( s ). This means that s is not optimal. square There may be several different schedules with no inversions. However, for each i = 1 ,... ,n , the job that appears i th in one such schedule has exactly the same waiting time as the job that appears i th in any other such schedule. Thus, all schedules with no inversions have the same total waiting time. Combining this with the Claim, we conclude that any schedule with no inversions is optimal. Our greedy algorithm then is to create a schedule in which jobs appear in increasing (more precisely: nondecreasing) duration, as suggested in the pseudocode below....
View
Full
Document
 Spring '08
 Pearly

Click to edit the document details