CPU Scheduling

Answer & solution
Official answer: 29.0
Our answer: 29
Step through it (10 steps)
1. P1 starts at 0. At 2, higher-priority P4 arrives and preempts it; P1 has 9 ms left. At 5, highest-priority P2 arrives and preempts P4, which has 7 ms left. P2 runs uninterrupted to 33; later arrivals P5 and P3 have lower priorities.
2. Among waiting processes, run P4 from 33–40, P1 from 40–49, P3 from 49–51, then P5 from 51–67. Completion times are C1=49,C2=33,C3=51,C4=40,C5=67.
3. With no I/O, waiting time equals completion minus arrival minus CPU burst. Thus W1=49-0-11=38; W2=33-5-28=0; W3=51-12-2=37; W4=40-2-10=28; W5=67-9-16=42. The total is 145, so the average is 145/5=29 ms. Do not confuse waiting time with turnaround, which also includes execution.