Hi Guys,
I am solving exercise problems from a book called Algorithms by Papadimitrou and Vazirani.
The following is the question:
A server has n customers waiting to be served. The service time required by each customer is known in advance: it is ti minutes for customer i. So if, for example, the customers are served in order of increasing i, then the ith customer has to wait for Sum(j = 1 to n) tj minutes.
We wish to minimize the total waiting time. Give an efficient algorithm for the same.
My Attempt:
I thought of a couple of approaches but couldnt decide which is best or any other approach that beats mine.
Approach 1:
Serve them in Round Robin fashion with time slice as 5. However, when i need to be more careful when deciding the time slice. It shouldnt be too high or low. So, i thought of selecting the time slice as the average of serving times.
Approach 2: Assume jobs are sorted according to the time they take and are stored in an array A[1...n]
First serve A[1] then A[n] then A[2] then A[n-1] and so on.
I cant really decide which will be a more optimal solution for this problem. Am i missing something.
Thanks, Chander