This preview shows pages 1–3. 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: Homework #3 (Solutions) 1. A new Indian restaurant called Mayura is gaining popularity amongst USC students due to its food quality. To improve customer service, the restaurant staff have decided to put up an online menu so that customers arrive at Mayura with their order choices already decided prior to arrival. However, every day, at 9 PM, several customers arrive simultaneously with dinner orders, and that becomes too much for the only chef at Mayura to handle, who can process only one order at a time. The chef complains to his miserly manager, who refuses to hire another chef. Instead, he resorts to the CSCI570 staff for suggestions about how the chef could sequence customer requests so as to minimize the average wait time, 1 n n i =1 w i , for each customer. (For example, if there are 3 customers with food preparation times (in minutes) t 1 = 2 ,t 2 = 4 ,t 3 = 3, and the customers are served in order (3 , 1 , 2), the wait times of customers are w 3 = 3 ,w 1 = 5 ,w 2 = 9, with average wait time of 17 3 .) (a) Give an efficient algorithm to find the optimal order to serve the customers with an analysis of running time and space requirements. Assume that all orders arrive at time 0. Solution Optimal Scheduling Algorithm: Serve customers in increasing of their preparation times. The time complexity is O ( n log n ) and space complexity is O ( n ). The space complexity is due to using Heapsort . Proof of Correctness: We apply an exchange argument. Suppose that is an optimal ordering which does not order the customers in increasing order of preparation times. Then there exists some i < j such that t ( i ) > t ( j ) . We construct a new ordering from that interchanges the positions of customers i and j as follows: ( k ) = ( i ) if k = j ( j ) if k = i ( k ) otherwise (1) Then we have W ( ) W ( ) = 1 n n X i =1 [( n k + 1)( t ( k ) > t ( k ) )] , (2) where W () is the average waiting time function with a given ordering as the argument. The RHS of Equation 2 evaluates to 1 n [( n i + 1)( t ( i ) t ( i ) ) + ( n j + 1)( t ( j ) t ( j ) )] , which equals 1 n [( n i + 1)( t ( j ) t ( i ) ) + ( n j + 1)( t ( i ) t ( j ) )] The above expression evaluates to 1 n ( j i )( t ( j ) t ( i ) ) < , which is a contradiction. Thus, the chefs strategy to service in increasing order of preparation times is optimal. (b) Suppose now that orders arrive at an integer time d i 0. Further assume that the chef can preempt; that is, he can stop working on an order, go to another order, and then return to an unfinished order later. Give an efficient algorithm that schedules the orders so as to minimize the average wait time of customers....
View
Full
Document
 '06
 Shamsian
 Algorithms

Click to edit the document details