Chapter 2

CPU Scheduling Algorithms (FCFS, RR, SJF, SRTN, Priority)

Apply algorithm rules and compute waiting/turnaround using Gantt charts.

Estimated time: 34 min

Each algorithm has a different rule for who runs next; this directly changes fairness and delay.

This topic is high-weight in papers and practical interviews because it combines concepts and calculation.

How to Solve Numericals

Added clarity

Clear explanation

For each algorithm: sort by rule, draw timeline, compute completion time, then derive turnaround and waiting.

What it really means

One consistent worksheet method prevents most arithmetic errors.

Example

Turnaround = completion - arrival; Waiting = turnaround - burst.

Key takeaway

Use a fixed solving pipeline for every question.

Trade-offs Between Algorithms

From notes

Clear explanation

No single algorithm wins all metrics; interactive systems often favor response while batch systems may favor throughput.

What it really means

Scheduling is policy design, not one-time formula memorization.

Key takeaway

Always justify algorithm choice using workload and metrics.

Round Robin: Step-by-Step

Added clarity

Clear explanation

Round Robin gives each ready process a fixed time quantum. If a process does not finish within quantum, it is preempted and pushed to queue tail.

What it really means

Like students answering one-by-one in class with a timer; unfinished student gets another turn later.

Example

For burst times [10,2,6,8,4] and quantum=3, the queue rotates repeatedly until each remaining burst reaches 0.

Key takeaway

Round Robin improves fairness and response, but quantum choice controls overhead.

FCFS, SJF, SRTN, Priority: How They Choose

Added clarity

Clear explanation

FCFS picks earliest arrival, SJF picks smallest next burst, SRTN keeps checking smallest remaining time, and Priority picks highest-priority process (preemptive or non-preemptive).

What it really means

These are different queue ordering rules applied at each scheduling decision point.

Example

If a short process arrives while a long one runs, SRTN may preempt immediately, but FCFS will not.

Key takeaway

Algorithm behavior is defined by selection rule + preemption policy.

FCFS Worked Example

Added clarity

Clear explanation

For P1(AT0,BT5), P2(AT1,BT3), P3(AT2,BT2), FCFS execution is P1(0-5), P2(5-8), P3(8-10).

What it really means

Arrival order is fixed, so later short jobs wait behind earlier long jobs.

Example

CT: [5,8,10], TAT: [5,7,8], WT: [0,4,6].

Key takeaway

Use CT -> TAT -> WT table format for scoring consistency.

Round Robin Rotation Example (q=2)

Added clarity

Clear explanation

A typical RR sequence with quantum 2 can be shown as P1 -> P2 -> P3 -> P1 -> P2 -> P1, with each unfinished process returning to queue tail.

What it really means

RR shares CPU in fair time slices rather than full completion turns.

Example

After each slice, subtract executed quantum from remaining burst and redraw queue order.

Key takeaway

Marks are often awarded for correct rotation steps even before final averages.

  • - Forgetting preemptive vs non-preemptive behavior
  • - Using wrong arrival order in tie cases
  • - Ignoring context-switch overhead when explicitly given
  • - FCFS: simple but convoy effect
  • - RR: fairness via time quantum
  • - SJF/SRTN: good average wait but possible starvation
  • - Priority: needs aging to reduce starvation
Turnaround Time (TAT) = Completion Time (CT) - Arrival Time (AT)
Waiting Time (WT) = TAT - Burst Time (BT)
Response Time (RT) = First Start Time - Arrival Time

Algorithm deep dive (how each scheduler works)

Use this as exam-ready explanation before solving numericals.

FCFS

Non-preemptive

Rule: Run jobs in arrival order.

  • - Pick earliest arrived process from ready queue.
  • - Run it until completion or blocking.
  • - Move to next in queue.

Good for: Simple batch systems and deterministic order.

Watch out: Convoy effect and poor average waiting time.

Round Robin

Preemptive

Rule: Each process gets a fixed time quantum in cyclic order.

  • - Take process from queue front.
  • - Run for min(quantum, remaining burst).
  • - If unfinished, push to queue end.

Good for: Interactive systems needing fairness and response.

Watch out: Quantum too small => high context switching overhead.

SJF

Non-preemptive

Rule: Choose process with smallest burst among ready jobs.

  • - When CPU becomes free, inspect ready jobs.
  • - Pick minimum burst time.
  • - Run until completion.

Good for: Low average waiting time in predictable workloads.

Watch out: Needs burst estimate and may starve long jobs.

SRTN

Preemptive

Rule: Always run job with shortest remaining time.

  • - Run current shortest remaining job.
  • - On each arrival, compare remaining times.
  • - Preempt if newcomer is shorter.

Good for: Fast completion of short jobs.

Watch out: Frequent preemption and starvation risk.

Priority

Preemptive or non-preemptive

Rule: Run highest-priority process first.

  • - Sort ready queue by priority value.
  • - Pick highest priority process.
  • - Apply aging to avoid starvation.

Good for: Systems with critical and non-critical task classes.

Watch out: Low-priority starvation without aging.

Exam lens for this topic

What evaluators usually expect in structured exam answers.

Must-use keywords

  • - Turnaround Time
  • - Waiting Time
  • - Response Time
  • - Preemptive
  • - Quantum

Answer flow

  • - Write algorithm rule in one line
  • - Draw ready-queue order and Gantt chart
  • - Compute CT, then TAT and WT table
  • - Conclude which algorithm behaves better for given workload

Diagram expectations

  • - Gantt chart

Repeated pattern: Same 5-process RR/FCFS table is frequently repeated in papers.

Mini quiz

Quick self-check from this topic before moving ahead.

1. Which algorithm is the preemptive version of SJF?

Practice Questions

  • Find average waiting time using FCFS and SJF for burst times 21,3,6,2.

    Source: Summer 2023 Q2(C)

    Answer focus: Correct Gantt sequence and metric calculation.

  • Apply Round Robin (q=3) for five processes and compute average TAT and WT.

    Source: Summer 2024 Q2(A)

    Answer focus: Correct rotation order with repeated arrivals at time 0.

Practice from papers (end-of-topic set)

These paper questions map directly to this topic. Solve now, then compare your structure with linked topics.

Question Bank Linked Here

Open all questions

How to answer linked exam questions

Full question bank

Extra clarity files

These are clearly marked additions, separate from source notes.