# Homework 1

#### Due 02/06/01

• Exercise 17.3-1, page 344.

• Exercise 17.3-6, page 344. NB: make sure your algorithm works even when the number of characters is even.

• Consider the following scheduling problem to minimize the average time a job spends in a system. For this problem, we have a single server and n jobs which take processing time t1, ..., tn. The server can process the jobs in any order, but once a job has started, the server must process the job until completion. All the jobs are submitted at time 0. The time that job i spends in the system is the sum of the time job i spends waiting while the processor is executing other jobs and ti.

For example, suppose that n=3, t1 = 7, t2 = 12, t3 = 4, and the processor executes the jobs in the order 2 1 3. Then the average waiting time is:

(12 + (12 + 7) + (12 + 7 + 4))/3 = 54/3 = 18.
A better order would be 1 3 2 (with an average time of 13.666), but even this is not optimal.

Devise a greedy algorithm to find the optimum ordering for this scheduling problem and prove that your algorithm produces the optimum ordering. State and briefly justify the running time of your algorithm.