CPU Scheduling Numericals: Worked Gantt Charts for FCFS, SJF, SRTF, Priority and RR

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

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

  1. 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?
  2. 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.
  3. Mark idle gaps. If nothing has arrived, the CPU is idle; do not slide the next process earlier.
  4. Read completion time (CT) for each process off the chart.
  5. Compute per process: turnaround TAT = CT - arrival, waiting WT = TAT - burst, response RT = first run - arrival.
  6. 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.

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.

Gantt charts for the same five processes under FCFS, SJF, SRTF and non-preemptive priority scheduling, with average waiting times of 9, 5.6, 5 and 7.8 ms.
The page's running example (P1 to P5) scheduled four ways. Each chart is computed by a simulator, not drawn by hand.

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

Common mistakes

Practice set

  1. P1-P4 arrive at 0 with bursts 6, 2, 8, 3 (that order). FCFS average WT?
  2. Same set, non-preemptive SJF average WT?
  3. SRTF: P1 (0, 5), P2 (1, 2), P3 (2, 6). Average TAT?
  4. RR, q = 3: P1, P2, P3 at 0 with bursts 7, 4, 2. Average WT?
  5. Non-preemptive priority (low number = high): P1 (0, 4, 2), P2 (1, 3, 3), P3 (2, 5, 1), P4 (3, 1, 4). Average WT?
  6. RR quantum 8 ms, switch cost 0.5 ms, all jobs long. Useful CPU fraction?
  7. Six processes finish in 48 ms. Throughput?
  8. Preemptive priority: P1 (0, 5, 3), P2 (1, 2, 1), P3 (2, 3, 2). When does P1 complete?
  9. A schedule has average TAT 12 ms and the average burst is 4.5 ms. Average WT?
Show answers
  1. 7.5 ms. Waits 0, 6, 8, 16; total 30.
  2. 4.5 ms. Order P2, P4, P1, P3; waits 0, 2, 5, 11.
  3. 6.67 ms. P1 0-1, P2 1-3, P1 3-7, P3 7-13; TATs 7, 2, 11.
  4. 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.
  5. 4.75 ms. P1 0-4, P3 4-9, P2 9-12, P4 12-13; waits 0, 8, 2, 9.
  6. About 94.1%. 8 / 8.5.
  7. 0.125 per ms (125 per second). 6 / 48.
  8. t = 10. P1 0-1, P2 1-3, P3 3-6, P1 6-10.
  9. 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

Interactive quiz loading. The first 10 questions are shown below.

  1. P2 arrives at t = 3 ms and needs 6 ms of CPU. The Gantt chart shows it running from 5 to 8 and again from 12 to 15. What are its waiting time and response time?

    1. WT = 6 ms, RT = 2 ms
    2. WT = 4 ms, RT = 2 ms
    3. WT = 6 ms, RT = 5 ms
    4. WT = 12 ms, RT = 2 ms
    Show answer

    Answer: A. WT = 6 ms, RT = 2 ms

    Turnaround = 15 - 3 = 12 ms, so waiting = 12 - 6 = 6 ms (2 ms before the first run plus the 4 ms gap from 8 to 12). Response time = first run - arrival = 5 - 3 = 2 ms.

  2. A Gantt chart for five processes ends at t = 25 ms, and all five finish by then. What is the throughput?

    1. 5 processes per ms
    2. 0.2 processes per ms (200 per second)
    3. 0.04 processes per ms (40 per second)
    4. 25 processes per second
    Show answer

    Answer: B. 0.2 processes per ms (200 per second)

    Throughput is the number of processes completed per unit time: 5 / 25 ms = 0.2 per ms, which is 200 per second. Dividing the other way (25 / 5 = 5 ms) gives the average time per completed process, not throughput.

  3. A schedule runs from t = 0 to t = 20 ms, and the Gantt chart shows the CPU idle from 3 to 6 ms because no process had arrived. Ignoring context switches, what is CPU utilisation?

    1. 85%
    2. 15%
    3. 70%
    4. 100%
    Show answer

    Answer: A. 85%

    Busy time = 20 - 3 = 17 ms out of 20 ms, so utilisation = 17/20 = 85%. The 3 ms idle gap counts against utilisation even though no process was waiting.

  4. For processes that do no I/O, under which kind of algorithm is each process's response time always equal to its waiting time?

    1. Round robin with any quantum
    2. SRTF
    3. Preemptive priority
    4. Any non-preemptive algorithm, such as FCFS or SJF
    Show answer

    Answer: D. Any non-preemptive algorithm, such as FCFS or SJF

    Under a non-preemptive algorithm a process runs its whole burst once it starts, so all its waiting happens before its first run: waiting time = first run - arrival = response time. Preemptive algorithms can add waiting after the first run.

  5. Six processes are in a round-robin ready queue at t = 0 and each needs more than 5 ms. The quantum is 5 ms and context switches are free. How long does the sixth process in the queue wait before it first gets the CPU?

    1. 30 ms
    2. 5 ms
    3. 20 ms
    4. 25 ms
    Show answer

    Answer: D. 25 ms

    Each of the five processes ahead of it uses a full 5 ms quantum, so the sixth starts at (n - 1) x q = 5 x 5 = 25 ms. 30 ms would be n x q, which wrongly counts its own quantum.

  6. In round robin, every quantum is 6 ms and every context switch costs 2 ms. All processes are long and CPU-bound. What fraction of time does the CPU spend on useful work?

    1. 67%
    2. 25%
    3. 80%
    4. 75%
    Show answer

    Answer: D. 75%

    Each cycle is 6 ms of work plus 2 ms of switching, so the useful fraction = 6 / (6 + 2) = 75%. 25% is the overhead share, and 67% wrongly divides 6 by 9.

  7. FCFS with (arrival, burst) in ms: P1 (0, 3), P2 (6, 4), P3 (7, 2). What is the average turnaround time?

    1. 5 ms
    2. 7 ms
    3. 4 ms
    4. 3 ms
    Show answer

    Answer: C. 4 ms

    The CPU is idle from 3 to 6. Gantt: P1 0-3, idle 3-6, P2 6-10, P3 10-12. TATs are 3, 4 and 5, so the average is 12/3 = 4 ms. Starting P2 at t = 3 instead of 6 is the common slip.

  8. Non-preemptive SJF, (arrival, burst) in ms: P1 (0, 5), P2 (1, 7), P3 (2, 2), P4 (3, 4), P5 (4, 1). What is the average waiting time?

    1. 7.8 ms
    2. 8 ms
    3. 3.8 ms
    4. 4.2 ms
    Show answer

    Answer: D. 4.2 ms

    P1 runs 0-5 because it is alone at t = 0. At t = 5 the shortest waiting job is P5 (1), then P3 (2), then P4 (4), then P2 (7). Gantt: P1 0-5, P5 5-6, P3 6-8, P4 8-12, P2 12-19. Waits are 0, 11, 4, 5 and 1, total 21, so the average is 4.2 ms.

  9. SRTF (preemptive SJF), (arrival, burst) in ms: P1 (0, 9), P2 (1, 4), P3 (3, 1), P4 (6, 5). What is the average waiting time?

    1. 5.75 ms
    2. 2.75 ms
    3. 7.5 ms
    4. 3.75 ms
    Show answer

    Answer: B. 2.75 ms

    Gantt: P1 0-1, P2 1-3, P3 3-4, P2 4-6, P4 6-11, P1 11-19. Completion times (P1 = 19, P2 = 6, P3 = 4, P4 = 11) give turnaround times; subtracting bursts gives waits totalling 11, so the average is 2.75 ms. Non-preemptive SJF would give 5.75 ms.

  10. Preemptive priority, lower number = higher priority. (arrival, burst, priority): P1 (0, 6, 3), P2 (2, 3, 1), P3 (3, 4, 4), P4 (4, 2, 2). When does P1 complete?

    1. t = 6 ms
    2. t = 11 ms
    3. t = 15 ms
    4. t = 9 ms
    Show answer

    Answer: B. t = 11 ms

    Gantt: P1 0-2, P2 2-5, P4 5-7, P1 7-11, P3 11-15. P2 preempts P1 at t = 2, P4 (priority 2) runs next, and P1 resumes for its last 4 ms, finishing at 11. 6 ms is the non-preemptive answer.

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.