{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

HW3 solutions - Homework#3(Solutions 1 A new Indian...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
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 σ 0 from σ that interchanges the positions of customers σ i and σ j as follows: σ 0 ( k ) = σ ( i ) if k = j σ ( j ) if k = i σ ( k ) otherwise (1) Then we have W ( σ 0 ) - W ( σ ) = 1 n n X i =1 [( n - k + 1)( t σ 0 ( 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 σ 0 ( i ) - t σ ( i ) ) + ( n - j + 1)( t σ 0 ( 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 ) ) < 0 ,
Image of page 1

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

View Full Document Right Arrow Icon
which is a contradiction. Thus, the chef’s 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. Solution Optimal Algorithm: The chef works on a order that is closest to completion time. He preempts the current order if a new order arrives which requires less time than the re- maining time on his current order. The time complexity is O ( n log n ).
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern