Question

In: Computer Science

Consider the following scheduling problem. There are n jobs and a single machine. Each job has...

Consider the following scheduling problem. There are n jobs and a single machine. Each job has a length ℓi and a weight wi . The weight wi represents the importance of job i.

a) Let fi be the finishing time of job i. Design a greedy algorithm to minimize the weighted sum of the completion times ∑n i=1 wifi . Your algorithm should run in time O(n log n) and output an ordering of the jobs.

b) Prove the correctness of your algorithm and analyze its running time.

Example: Suppose there are two jobs: t1 = 1, w1 = 2, t2 = 3, and w2 = 1. Doing job 1 first would give f1 = 1, f2 = 4, and a weighted sum of 2 · 1 + 1 · 4 = 6, which is optimal. Doing job 2 first would yield f1 = 4, f2 = 3, and a larger weighted sum of 2 · 4 + 1 · 3 = 11. (Hint: how does the weighted sum change if we swap two adjacent jobs?)

Solutions

Expert Solution

Solution (a): Algorithm:

Step 1. For each job calculate the ratio, calculate the ratio wi / li i.e., weight per unit length

Step 2. Order all the jobs on the basis of calculated weigth per unit length in descending order and return this order.

Solution (b): Correctness proof -

       Suppose O is an optimal solution which is having weight W. Now let we swap the order of any pair of jobs Ji(=wi/li) and Jj(=wj/lj), then this swapping will result in change of weighted sum from W to W'.This change is only because of two swapped adjacent jobs as the completion time of other remaining jobs will remain same.
 
Now for W' to be smaller than W, it is required that two jobs Ji and Jj must be order in descending order of weight per length order. ---(1)

If the order of Ji and Jj is ascneding, then W'>W and thus O will not be optimal solution. Thus for any two adjacent jobs, argument 1 applies for the solution to be optimal and thus we can conclude that whole order will be descending in order of weight per length ratio.

Running time analysis:- Step 1 requires only one pass over all the given jobs and thus takes O(n), step 2 requires sorting on basis of weight per length and thus takes O(n log n). Thus, as a whole algorithm takes O(n) + O(n log n) = O(n log n) time.

Related Solutions

Consider the following variant of the Interval Scheduling problem. There are n jobs and each job...
Consider the following variant of the Interval Scheduling problem. There are n jobs and each job has a start time si and an end time fi . There is a single machine that can run at most one job at any given time. The jobs are now daily jobs. Once accepted, it must run continuously every day between its start and end times. (Note that a job can start before midnight and end after midnight.) a) Design an algorithm that...
Consider a job mix in which there is one CPU-intensive job, A, that has a single...
Consider a job mix in which there is one CPU-intensive job, A, that has a single infinitely long CPU burst, and 3 I/O-intensive jobs, B, C, and D. The scheduler uses Round Robin scheduling with a time quantum of 3 ms. Here is an observed execution, where initially A is running and B, C, and D are in the ready queue in this order: AAAoBBoCoDoAAAoBBoAAAoDoAAAoBBoCoDoAAAoBBo Answer the following questions based on the above. Explain and give a specify a part...
The following processing times were obtained for an N-job, three-machine problem. Find the minimum makespan schedule....
The following processing times were obtained for an N-job, three-machine problem. Find the minimum makespan schedule. Job Machine 1 Machine 2 Machine 3 1 10 1 7 2 12 3 10 3 8 5 9 4 9 2 11 5 7 4 12 6 11 6 8 Determine the optimal makespan schedule. What is the optimal makespan?
Consider the following set of jobs to be scheduled for execution on a single CPU system....
Consider the following set of jobs to be scheduled for execution on a single CPU system. Job Arrival Time Burst (msec) Priority A 0 6 3 (Silver) B 1 2 1 (Diamond) C 3 5 3 (Silver) D 5 3 4 (Bronze) E 7 2 2 (Gold)    (a)     Draw a Gantt chart showing First-Come-First-Served (FCFS) scheduling for these jobs. (b)     Draw a Gantt chart showing preemptive PRIORITY scheduling. (c)    Draw a Gantt chart showing Highest Response Ratio Next (HRRN) scheduling. (d)     Draw a...
Consider the following set of jobs to be scheduled for execution on a single CPU system....
Consider the following set of jobs to be scheduled for execution on a single CPU system. Job Arrival Time Burst (msec) Priority A 0 6 3 (Silver) B 1 2 1 (Diamond) C 3 5 3 (Silver) D 5 3 4 (Bronze) E 7 2 2 (Gold)    Draw a Gantt chart showing First-Come-First-Served (FCFS) scheduling for these jobs.       Draw a Gantt chart showing preemptive PRIORITY scheduling. Draw a Gantt chart showing Highest Response Ratio Next (HRRN) scheduling.     Draw a...
Consider the following set of jobs to be scheduled for execution on a single CPU system....
Consider the following set of jobs to be scheduled for execution on a single CPU system. Job Arrival Time Burst (msec) Priority A 0 6 3 (Silver) B 1 2 1 (Diamond) C 3 5 3 (Silver) D 5 3 4 (Bronze) E 7 2 2 (Gold)    (a)     Draw a Gantt chart showing First-Come-First-Served (FCFS) scheduling for these jobs. (b)     Draw a Gantt chart showing preemptive PRIORITY scheduling. (c)    Draw a Gantt chart showing Highest Response Ratio Next (HRRN) scheduling. (d)     Draw a...
Consider the following set of jobs to be scheduled for execution on a single CPU system....
Consider the following set of jobs to be scheduled for execution on a single CPU system. Job Arrival Time Burst (msec) Priority A 0 6 3 (Silver) B 1 2 1 (Diamond) C 3 5 3 (Silver) D 5 3 4 (Bronze) E 7 2 2 (Gold)    (a) Draw a Gantt chart showing First-Come-First-Served (FCFS) scheduling for these jobs. [3 Marks] Answer (a) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...
There are n processes in a queue. Each process has namei and timei. The round-robin scheduling...
There are n processes in a queue. Each process has namei and timei. The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a quantum (a time slot) and interrupts the process if it is not completed by then. The process is resumed and moved to the end of the queue, then the scheduler handles the next process in the queue. For example, we have the following queue with the quantum of 100ms. A(150) - B(80)...
There are n processes in a queue. Each process has namei and timei. The round-robin scheduling...
There are n processes in a queue. Each process has namei and timei. The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a quantum (a time slot) and interrupts the process if it is not completed by then. The process is resumed and moved to the end of the queue, then the scheduler handles the next process in the queue. For example, we have the following queue with the quantum of 100ms. A(150) - B(80)...
There are 5 jobs that have to be scheduled in a two-machine job shop system. The...
There are 5 jobs that have to be scheduled in a two-machine job shop system. The processing time and the sequence of the required operations of these jobs on the two machines are shown in the table below. For example, job A needs 6 hours on machine 1 (M1) and 4 hours on machine 2 (M2), and it has to be processed on M1 and then M2. You have to use the shortest processing time (SPT) rule to schedule the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT