95%(37)35 out of 37 people found this document helpful
This preview shows page 86 - 88 out of 131 pages.
(a) We want to minimize the average waiting time (the average of the amount of time each customer waitsbefore they are seen, not counting the time they spend with the doctor). What order should we use?Hint: sort the customers by.2.)Solution:First observe that swappingxiandxjdoes not affect the waiting time customersx1,x2,...,xior cus-tomersxj+1,xj+1,...,xn(i.e., for customersxkwherekiork>j). Therefore we only have to dealwith customersxi+1,...,xj, i.e., for customerk, wherei<kj. For customerxk, the waiting timebefore the swap isTk=Â1l<kt(xl),and the waiting time after the swap isT0k=Â1l<it(xl)+t(xj)+Âi<l<kt(xl) =Tk-t(xi)+t(xj).Sincet(xi)≥t(xj),T0kTk, so the waiting time is never increased for customersxi+1,...,xj, hence theaverage waiting time for all the customers will not increase after the swap.(c) Letube the ordering of customers you selected in part (a), andxbe any other ordering. Prove that theaverage waiting time ofuis no larger than the average waiting time ofx—and therefore your answerin part (a) is optimal.Hint: Letibe the smallest index such thatui6=xi. Use what you learned in part (b). Then, use proofby induction (maybe backwards, in the orderi=n,n-1,n-2,...,1, or in some other way).Solution:Letube the ordering in part (a), andxbe any other ordering. Letibe the smallest index such thatui6=xi. Letjbe the index ofxiinu, i.e,xi=ujandkbe the index ofuiinx. It’s easy to see thatj>i.By the construction ofx, we haveT(xi) =T(uj)≥T(ui) =T(xk), therefore by swappingxiandxk, wewill not increase the average waiting time. If we keep doing this, eventually we will transformxintou. Since we never increase the average waiting time throughout the process,uis the optimal ordering.3. (15 pts.)Job SchedulingYou are given a set ofnjobs. Each takes one unit of time to complete. Jobihas an integer-valued deadlinetimedi≥0 and a real-valued penaltypi≥0. Jobs may be scheduled to start at any non-negative integerCS 170, Fall 2014, Soln 73
time (0, 1, 2, etc), and only one job may run at a time. If jobicompletes at or before timedi, then it incursno penalty; otherwise, it is late and incurs penaltypi. The goal is to schedule all jobs so as to minimize thetotal penalty incurred.