GATE / CS ARCHIVE

SIMILAR QUESTIONS / OPERATING SYSTEMS

Minimize waiting with shortest job order

3 questions solved the same way, newest first. Back to Operating Systems

How these are solved

For CPU-bound jobs available together with known bursts, shortest-processing-time order minimizes sum waiting. 1998 gives a symbolic burst and asks order;

1 mark · NAT
Report issue

CPU Scheduling

Question 25, GATE 2021: Three processes arrive at time zero with CPU bursts 16,20,10 milliseconds. With prior burst knowledge and non-preemptive scheduling, what is the minimum average waiting time, rounded to the nearest integer in milliseconds?
Tap to enlarge
Answer & solution

Official answer: 12

Shortest-job-first minimizes total waiting time when all jobs arrive together and burst lengths are known. Execute bursts 10, 16, 20. Their waiting times are 0, 10, 26, whose average is 36/3=12 milliseconds.

For three jobs of lengths a,b,c in that order, total waiting is 0+a+(a+b)=2a+b. Placing shorter jobs earlier minimizes this weighted sum. More generally, swapping adjacent lengths x>y reduces the waiting total by x−y while leaving later completion times unchanged. This exchange argument proves shortest-job-first is optimal here. Completion/turnaround times would be 10,26,46 and are not the requested waiting times.

Original paper, page 22 · Answer key

1 mark · MCQ
Report issue

CPU Scheduling

Question 20, GATE 2016: CPU-bound processes with unequal burst lengths all arrive simultaneously. Which scheduling policy minimizes average ready-queue waiting time? A: shortest remaining time first. B: round robin with quantum shorter than every burst. C: uniform random. D: highest priority first, with priority proportional to burst length.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

All processes are available initially and are CPU-bound, so shortest-remaining-time-first reduces to shortest-job-first. If a longer job immediately precedes a shorter one, swapping them reduces the sum of waiting times by the burst-length difference. Repeated exchanges yield increasing burst order, which is optimal. Thus A.

Suppose adjacent bursts have lengths a>b. Executing a before b contributes a to b's wait, whereas reversing them contributes b to a's wait; completion time of the pair and waits of later jobs stay unchanged. The swap decreases total wait by a−b. Eliminating all such inversions gives ascending burst order. Since all arrivals occur at time zero, no newly arriving short job triggers a distinct preemption issue; SRTF executes this same optimal order.

Original paper, page 10 · Answer key

Descriptive
Report issue

Minimum average job response

CPU Scheduling

Question 24(a), GATE 1998: Four jobs with expected run times 6,3,5,x are waiting. In what order should they run to minimize average response time?
Question 24(a), GATE 1998: Four jobs with expected run times 6,3,5,x are waiting. In what order should they run to minimize average response time?
Tap to enlarge
Answer & solution

Answer: Shortest expected processing time first, subject to standard all-arrived nonpreemptive assumptions. (no official key was published)

Assume one processor, all four jobs ready at time zero, no scheduling overhead, and response interpreted as time to completion (or waiting time to first execution under nonpreemptive execution). Consider adjacent jobs of lengths a>b starting at time t. Their completion-time sum in order a,b is (t+a)+(t+a+b)=2t+2a+b. Reversing them gives 2t+2b+a, smaller by a−b. Other jobs' completion times do not change, because the pair's total length is unchanged. Repeatedly removing inversions proves ascending processing time is optimal.

Thus for x≥0: if x≤3, use x,3,5,6; if 3≤x≤5, use 3,x,5,6; if 5≤x≤6, use 3,5,x,6; if x≥6, use 3,5,6,x. Ties can be broken either way. For random run times the same exchange proof minimizes expected mean completion using their expected durations, when the decision is a fixed order and those expectations are known.

The answer is not a universal interactive-response policy: different release times, preemption or defining response as first service with arbitrarily small time slices changes the optimization problem. These are not specified, so the conventional nonpreemptive model is stated.

Original paper, page 8