Five processes arrive together with bursts 10, 1, 2, 1, 5 and priorities 3, 1, 4, 5, 2 (lower number is higher priority). What is the average waiting time under non-preemptive priority scheduling?
The order is P2, P5, P1, P3, P4. Waiting times are 0, 1, 6, 16 and 18, a total of 41, so the average is 41 / 5 = 8.2 ms.
Explain it simply
Priority scheduling serves the most important job first, like a hospital casualty ward seeing the most serious patient before the one with a cough. Here a smaller number means higher priority, and the chosen process runs to completion.
| Process | Burst | Priority |
|---|---|---|
| P1 | 10 | 3 |
| P2 | 1 | 1 |
| P3 | 2 | 4 |
| P4 | 1 | 5 |
| P5 | 5 | 2 |
Example
Sort by priority number: P2 (1), P5 (2), P1 (3), P3 (4), P4 (5).
| P2 | P5 | P1 | P3 | P4 |
0 1 6 16 18 19Waiting time = start time, since all arrive at 0:
- P2: 0
- P5: 1
- P1: 6
- P3: 16
- P4: 18
Total = 0 + 1 + 6 + 16 + 18 = 41. Average = 41 / 5 = 8.2 ms.
Notice that P4 has a tiny burst of 1 ms yet waits 18 ms because its priority is lowest. If higher-priority jobs kept arriving, P4 could wait forever. That is starvation, and aging is the usual fix.
What to say in the interview
"I sort by priority, lowest number first: P2, P5, P1, P3, P4. Start times are 0, 1, 6, 16 and 18, which add to 41, so the average wait is 8.2 ms. I'd also mention starvation of low-priority jobs and aging as the cure."
Common mistakes
- Treating a larger number as higher priority without checking the convention in the question.