AlgoFrames

Round-robin finish times

Standard · Write code · about 15 min

Process i arrives at arrival[i] and needs burst[i] units of CPU. Round robin keeps a FIFO queue of ready processes. The front process runs for min(quantum, time left). If it is not done, it goes to the back of the queue, after any process that arrived up to and including that moment. Processes arriving at the same time join in index order. The CPU idles when the queue is empty.

Return an array whose i-th value is the time process i finishes.

Example 1

Input:

[[0,1,2],[5,3,4],2]

Output:

[12,9,11]

Example 2

Input:

[[0,0],[3,3],5]

Output:

[3,6]

A quantum longer than every burst behaves like FCFS.

Constraints

  • 1 ≤ n ≤ 1,000, where n = arrival.length = burst.length
  • 0 ≤ arrival[i] ≤ 1,000
  • 1 ≤ burst[i] ≤ 100
  • 1 ≤ quantum ≤ 20

Learn the idea first: CPU scheduling: FCFS, SJF, priority, round robin, a visual lesson.

More CPU scheduling: FCFS, SJF, priority, round robin problems