The following table shows the processes in the ready queue and time required…

2011

The following table shows the processes in the ready queue and time required for each process for completing its job.

Process    Time
P1          10
P2          5
P3          20
P4          8
P5          15

Assume all processes arrive at time 0, in the order P1, P2, P3, P4, P5 (no arrival times are given in the table).

If round-robin scheduling with 5 ms is used what is the average waiting time of the processes in the queue?

  1. A.

    27 ms

  2. B.

    26.2 ms

  3. C.

    27.5 ms

  4. D.

    27.2 ms

Attempted by 99 students.

Show answer & explanation

Correct answer: B

Concept

Round Robin (RR) is a preemptive CPU-scheduling algorithm: every ready process is given the CPU for at most one fixed time quantum, after which it is preempted and sent to the tail of the ready queue if it still has work left. Processes are served in a circular (FIFO) fashion until each finishes.

Key definitions used below: Completion Time (CT) is the instant a process finishes; Waiting Time (WT) = CT - Burst Time - Arrival Time; the average waiting time is the mean of all the WT values.

Assumption on arrival time: when a problem gives no arrival times, the standard convention is that all processes arrive together at time 0 and enter the ready queue in the listed order (P1, P2, P3, P4, P5). With arrival time = 0 for every process, the waiting-time formula simplifies to WT = CT - Burst Time.

Step 1 - Build the Gantt chart (quantum = 5 ms)

Cycle through the queue, giving each process 5 ms (or its remaining time, whichever is smaller). A process that still has time left re-joins the back of the queue. Remaining bursts start at P1=10, P2=5, P3=20, P4=8, P5=15.

  1. 0-5: P1 runs (10 -> 5 left, requeued)

  2. 5-10: P2 runs (5 -> 0, P2 finishes, CT = 10)

  3. 10-15: P3 runs (20 -> 15 left, requeued)

  4. 15-20: P4 runs (8 -> 3 left, requeued)

  5. 20-25: P5 runs (15 -> 10 left, requeued)

  6. 25-30: P1 runs (5 -> 0, P1 finishes, CT = 30)

  7. 30-35: P3 runs (15 -> 10 left, requeued)

  8. 35-38: P4 runs (3 -> 0, P4 finishes, CT = 38)

  9. 38-43: P5 runs (10 -> 5 left, requeued)

  10. 43-48: P3 runs (10 -> 5 left, requeued)

  11. 48-53: P5 runs (5 -> 0, P5 finishes, CT = 53)

  12. 53-58: P3 runs (5 -> 0, P3 finishes, CT = 58)

Step 2 - Waiting Time = Completion Time - Burst Time

Process

Burst Time

Completion Time

Waiting Time (CT - BT)

P1

10

30

30 - 10 = 20

P2

5

10

10 - 5 = 5

P3

20

58

58 - 20 = 38

P4

8

38

38 - 8 = 30

P5

15

53

53 - 15 = 38

Step 3 - Average waiting time

Sum of waiting times = 20 + 5 + 38 + 30 + 38 = 131 ms.

Average waiting time = 131 / 5 = 26.2 ms.

Cross-check

The last process to finish (P3) completes at t = 58 ms, which equals the total of all burst times (10 + 5 + 20 + 8 + 15 = 58) - consistent because RR has no idle gaps when every process is present from t = 0. The average turnaround time is (30 + 10 + 58 + 38 + 53)/5 = 37.8 ms, and 37.8 - (58/5 average burst = 11.6) = 26.2 ms, matching the average waiting time.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Isro