CPU Scheduling Numericals: Worked Gantt Charts for FCFS, SJF, SRTF, Priority and RR
A CPU scheduling numerical gives you a table of processes (arrival time, CPU burst and sometimes a priority) and asks for a Gantt chart, a completion time, or the average waiting, turnaround or response time under FCFS, SJF, SRTF, priority or round robin. You solve every one the same way: draw the chart first, then read the numbers off it. Operating Systems carries 5% of the NSCT according to HEC's Areas of Competencies, and it had the lowest accuracy of any area in 2026, at 33.8%, per the HEC NSCT report and APP.
This page assumes you know what each algorithm does; if not, read CPU Scheduling first. Here we push one five-process set through every algorithm so you can see exactly where the answers diverge.
The method, step by step
- Copy the table and note the rules. Preemptive or not? For priority, is a lower number higher priority? For round robin, what is the quantum, and does a new arrival join the queue before or after a process preempted at the same instant?
- Draw the time axis. At every decision point (a completion, an arrival for preemptive algorithms, a quantum expiry for RR) list who is ready and pick by the rule.
- Mark idle gaps. If nothing has arrived, the CPU is idle; do not slide the next process earlier.
- Read completion time (CT) for each process off the chart.
- Compute per process: turnaround TAT = CT - arrival, waiting WT = TAT - burst, response RT = first run - arrival.
- Average by dividing the column totals by the number of processes. Check: average TAT - average WT must equal the average burst.
The running example
Every worked answer below uses this set (times in ms, lower priority number = higher priority):
| Process | Arrival | Burst | Priority |
|---|---|---|---|
| P1 | 0 | 7 | 3 |
| P2 | 2 | 4 | 1 |
| P3 | 3 | 9 | 4 |
| P4 | 5 | 3 | 2 |
| P5 | 6 | 2 | 5 |
The bursts total 25 ms and there are no idle gaps, so every algorithm finishes at t = 25 and the throughput is always 5/25 = 0.2 processes per ms. The average burst is 5 ms, so average TAT - average WT = 5 in every case.
FCFS: first come, first served
Run in arrival order, no preemption.
| Gantt | P1 0-7 | P2 7-11 | P3 11-20 | P4 20-23 | P5 23-25 |
|---|---|---|---|---|---|
| Process | CT | TAT | WT |
|---|---|---|---|
| P1 | 7 | 7 | 0 |
| P2 | 11 | 9 | 5 |
| P3 | 20 | 17 | 8 |
| P4 | 23 | 18 | 15 |
| P5 | 25 | 19 | 17 |
| Average | 14 | 9 |
Idle-gap example. With P1 (0, 2), P2 (5, 3) and P3 (6, 4), the chart is P1 0-2, idle 2-5, P2 5-8, P3 8-12. Waits are 0, 0 and 2, so the average is 0.67 ms, and CPU utilisation is 9 busy ms out of 12, or 75%.
SJF: shortest job first (non-preemptive)
At each completion, pick the shortest burst among the processes that have already arrived. At t = 0 only P1 exists, so it runs all 7 ms. At t = 7 the queue holds P2 (4), P3 (9), P4 (3) and P5 (2).
| Gantt | P1 0-7 | P5 7-9 | P4 9-12 | P2 12-16 | P3 16-25 |
|---|---|---|---|---|---|
Waits: P1 0, P2 10, P3 13, P4 4, P5 1. Total 28, so average WT = 5.6 ms and average TAT = 10.6 ms.
SRTF: shortest remaining time first
Re-decide at every arrival: a newcomer preempts if its burst is shorter than the running process's remaining time.
- t = 2: P2 (4) beats P1's remaining 5, so P1 is preempted.
- t = 3 and t = 5: P3 (9) and P4 (3) do not beat P2's remaining 3 and 1.
- t = 6: P2 finishes; the shortest is P5 (2), then P4 (3), then P1 (5), then P3 (9).
| Gantt | P1 0-2 | P2 2-6 | P5 6-8 | P4 8-11 | P1 11-16 | P3 16-25 |
|---|---|---|---|---|---|---|
| Process | CT | TAT | WT | RT |
|---|---|---|---|---|
| P1 | 16 | 16 | 9 | 0 |
| P2 | 6 | 4 | 0 | 0 |
| P3 | 25 | 22 | 13 | 13 |
| P4 | 11 | 6 | 3 | 3 |
| P5 | 8 | 2 | 0 | 0 |
| Average | 10 | 5 | 3.2 |
SRTF gives the lowest average waiting time of the five algorithms here, as theory predicts.

Priority scheduling (both versions)
Non-preemptive: P1 runs 0-7. At t = 7 the best priorities waiting are P2 (1), then P4 (2), P3 (4) and P5 (5).
| Gantt | P1 0-7 | P2 7-11 | P4 11-14 | P3 14-23 | P5 23-25 |
|---|---|---|---|---|---|
Waits 0, 5, 11, 6 and 17: average WT = 7.8 ms.
Preemptive: P2 (priority 1) preempts P1 at t = 2. P4 (priority 2) arrives at 5 but cannot beat P2.
| Gantt | P1 0-2 | P2 2-6 | P4 6-9 | P1 9-14 | P3 14-23 | P5 23-25 |
|---|---|---|---|---|---|---|
Waits 7, 0, 11, 1 and 17: average WT = 7.2 ms, average RT = 5.8 ms. P5, the lowest priority, waits 17 ms in both versions; with a steady stream of higher-priority arrivals it would starve, which is what aging fixes.
Round robin (quantum 2 ms)
Rule used: a new arrival joins the queue before the process preempted at the same instant. Track the queue after each slice:
| Slice | Runs | Queue afterwards |
|---|---|---|
| 0-2 | P1 | P2, P1 |
| 2-4 | P2 | P1, P3, P2 |
| 4-6 | P1 | P3, P2, P4, P5, P1 |
| 6-8 | P3 | P2, P4, P5, P1, P3 |
| 8-10 | P2 (done) | P4, P5, P1, P3 |
| 10-12 | P4 | P5, P1, P3, P4 |
| 12-14 | P5 (done) | P1, P3, P4 |
| 14-16 | P1 | P3, P4, P1 |
| 16-18 | P3 | P4, P1, P3 |
| 18-19 | P4 (done) | P1, P3 |
| 19-20 | P1 (done) | P3 |
| 20-25 | P3 (done) | empty |
Completion times: P1 20, P2 10, P3 25, P4 19, P5 14. Waits 13, 4, 13, 11 and 6: average WT = 9.4 ms, average TAT = 14.4 ms. But average RT is only 2.8 ms, the best of any algorithm here.
Comparing the results
| Algorithm | Avg TAT | Avg WT | Avg RT |
|---|---|---|---|
| FCFS | 14 | 9 | 9 |
| SJF | 10.6 | 5.6 | 5.6 |
| SRTF | 10 | 5 | 3.2 |
| Priority (non-preemptive) | 12.8 | 7.8 | 7.8 |
| Priority (preemptive) | 12.2 | 7.2 | 5.8 |
| RR, q = 2 | 14.4 | 9.4 | 2.8 |
Two patterns to remember: SRTF wins on waiting time, and RR wins on response time while losing on turnaround. For non-preemptive algorithms, RT always equals WT.
Context-switch cost. The RR chart has 12 separate runs, so 11 switches. If each switch cost 0.5 ms, the schedule would take 25 + 5.5 = 30.5 ms and utilisation would fall to 25/30.5, about 82%.
Speed tricks
- All arrive at t = 0? For FCFS and SJF, each wait is just the sum of the bursts ahead of it, so you can skip the chart.
- Use the invariant. Find average TAT, then subtract the average burst to get average WT (or the reverse).
- SRTF shortcut: only arrivals can cause preemption, so you only re-decide at arrival times and completions.
- RR with a quantum bigger than every burst is FCFS. Spot it and reuse the FCFS answer.
- Round only at the end. Keep totals as integers (28/5, not 5.6 per row).
Common mistakes
- Starting a process before it has arrived, especially after an idle gap.
- Using CT as TAT when arrival is not 0, or computing CT - burst and forgetting to subtract arrival.
- In non-preemptive SJF, choosing a short job that has not arrived yet at the decision point.
- In SRTF, comparing a newcomer's burst with the running process's original burst instead of its remaining time.
- Mixing up the RR queue order at simultaneous events. State the rule you used if the stem does not.
- Reading "priority 1" as the lowest priority without checking the question's convention.
Practice set
- P1-P4 arrive at 0 with bursts 6, 2, 8, 3 (that order). FCFS average WT?
- Same set, non-preemptive SJF average WT?
- SRTF: P1 (0, 5), P2 (1, 2), P3 (2, 6). Average TAT?
- RR, q = 3: P1, P2, P3 at 0 with bursts 7, 4, 2. Average WT?
- Non-preemptive priority (low number = high): P1 (0, 4, 2), P2 (1, 3, 3), P3 (2, 5, 1), P4 (3, 1, 4). Average WT?
- RR quantum 8 ms, switch cost 0.5 ms, all jobs long. Useful CPU fraction?
- Six processes finish in 48 ms. Throughput?
- Preemptive priority: P1 (0, 5, 3), P2 (1, 2, 1), P3 (2, 3, 2). When does P1 complete?
- A schedule has average TAT 12 ms and the average burst is 4.5 ms. Average WT?
Show answers
- 7.5 ms. Waits 0, 6, 8, 16; total 30.
- 4.5 ms. Order P2, P4, P1, P3; waits 0, 2, 5, 11.
- 6.67 ms. P1 0-1, P2 1-3, P1 3-7, P3 7-13; TATs 7, 2, 11.
- 6.67 ms. P1 0-3, P2 3-6, P3 6-8, P1 8-11, P2 11-12, P1 12-13; waits 6, 8, 6.
- 4.75 ms. P1 0-4, P3 4-9, P2 9-12, P4 12-13; waits 0, 8, 2, 9.
- About 94.1%. 8 / 8.5.
- 0.125 per ms (125 per second). 6 / 48.
- t = 10. P1 0-1, P2 1-3, P3 3-6, P1 6-10.
- 7.5 ms. 12 - 4.5.
Practise
The quiz below has 20 CPU scheduling numericals, filterable by tier and difficulty, and every answer was computed by a scheduler simulator.
Practise: 20 questions
FAQs
Which CPU scheduling algorithm gives the minimum average waiting time?
For processes that are all available together, SJF is optimal. When arrivals are staggered, its preemptive form, SRTF, gives the minimum, as the running example shows (5 ms against SJF's 5.6 ms). Both need the burst lengths in advance, which a real OS can only estimate.
How do I handle ties in SJF or round robin?
Use the rule in the question. If none is given, the common convention breaks SJF ties by arrival order (FCFS) and, in round robin, places a newly arrived process ahead of the one just preempted. Write down the rule you chose, because a different rule can change the answer.
Do I include context-switch time in waiting time?
Only if the question gives a switch cost. Most numericals say "ignore context switching". If a cost is given, add it to the timeline between runs; it then pushes back completion times and lowers CPU utilisation.
Why is round robin's turnaround worse than FCFS sometimes?
Interleaving delays every job's completion. In the running example RR's average TAT is 14.4 ms against FCFS's 14 ms, but it starts each process far sooner, so its response time is much better. RR is built for interactivity, not turnaround.
Next step
Revise the concepts in CPU Scheduling, then move on to page replacement numericals. Return to the Operating Systems MCQ hub or test yourself under time pressure in the NSCT mock test.