Average waiting time under SJF — Aptitude Question
Average waiting time under SJF: Four processes are all present at time 0: | Process | Burst time |… Answer and worked solution on CodeKairo.
- Topic: OS, DBMS & Networks
- Section: Programming MCQs
- Difficulty: Medium
- Time target: 120 seconds
Question
Four processes are all present at time 0:
| Process | Burst time |
|---|---|
| P1 | 6 |
| P2 | 8 |
| P3 | 7 |
| P4 | 3 |
Under non-preemptive shortest-job-first scheduling, what is the average waiting time?
Options
- 5.50
- 7.00
- 7.75
- 8.25
Show the answer and the worked solution
Correct answer: B. 7.00
Worked solution
- All four are ready at time 0, so SJF runs them in burst order: P4, P1, P3, P2.
- The schedule is P4 from 0 to 3, P1 from 3 to 9, P3 from 9 to 16 and P2 from 16 to 24.
- The waiting times are P4 = 0, P1 = 3, P3 = 9 and P2 = 16.
- The total is 0 + 3 + 9 + 16 = 28, so the average is 28 / 4 = 7.00 units.
Answer: 7.00.
The idea
SJF provably minimises average waiting time for a fixed set of jobs, which is why it is the benchmark every other algorithm is measured against. Its problem is that burst lengths must be predicted, and long jobs can starve.
Shortcut. Sort the bursts to 3, 6, 7, 8; each delays every job after it, so the total wait is 3 × 3 + 6 × 2 + 7 × 1 = 28, and 28 ÷ 4 = 7.
Common trap. 7.75 runs P1 first because it is listed first and only then goes shortest-first, giving waits 0, 6, 9 and 16, which total 31.