Consider the set of process with arrival time (in milliseonds), CPU burst time…
2017
Consider the set of process with arrival time (in milliseonds), CPU burst time (in millisecods) and priority (0 is the highest priority) shown below. None of the process have I/O burst time

The average waiting time (in milli seconds) of all the process using premtive priority scheduling algorithm is ______
Attempted by 131 students.
Show answer & explanation
Correct answer: 29
Key idea: use preemptive priority scheduling (lower priority number means higher priority). A running process is preempted when a newly arrived process has a smaller priority value.
Timeline of execution:
0–2: P1 runs (P1 remaining = 9).
2–5: P4 runs (P4 remaining = 7) after arriving at 2 with higher priority than P1.
5–33: P2 runs (arrives at 5 with highest priority 0) and completes at 33.
33–40: P4 resumes and completes at 40.
40–49: P1 resumes and completes at 49.
49–51: P3 runs (arrived at 12) and completes at 51.
51–67: P5 runs (arrived at 9) and completes at 67.
Now compute waiting time = completion time − arrival time − burst time for each process.
P1: completion 49, arrival 0, burst 11 → waiting = 49 − 0 − 11 = 38
P2: completion 33, arrival 5, burst 28 → waiting = 33 − 5 − 28 = 0
P3: completion 51, arrival 12, burst 2 → waiting = 51 − 12 − 2 = 37
P4: completion 40, arrival 2, burst 10 → waiting = 40 − 2 − 10 = 28
P5: completion 67, arrival 9, burst 16 → waiting = 67 − 9 − 16 = 42
Average waiting time = (38 + 0 + 37 + 28 + 42) / 5 = 145 / 5 = 29 milliseconds.
A video solution is available for this question — log in and enroll to watch it.