Round Robin Scheduling
Preemptive scheduling with fixed time quantum. Each process gets equal CPU time slices.
Visualization
Interactive visualization for Round Robin Scheduling
Round Robin:
- • Time-sharing scheduling
- • Each process gets time quantum
Interactive visualization with step-by-step execution
Implementation
1function roundRobinScheduling(processes: {id: number; burstTime: number}[], quantum: number): {avgWaitTime: number} {
2 const remaining = processes.map(p => p.burstTime);
3 const waitTime = Array(processes.length).fill(0);
4 let currentTime = 0;
5
6 while (true) {
7 let done = true;
8 for (let i = 0; i < processes.length; i++) {
9 if (remaining[i] > 0) {
10 done = false;
11 if (remaining[i] > quantum) {
12 currentTime += quantum;
13 remaining[i] -= quantum;
14 } else {
15 currentTime += remaining[i];
16 waitTime[i] = currentTime - processes[i].burstTime;
17 remaining[i] = 0;
18 }
19 }
20 }
21 if (done) break;
22 }
23
24 return {avgWaitTime: waitTime.reduce((a, b) => a + b, 0) / processes.length};
25}Deep Dive
Theoretical Foundation
Each process allocated fixed time quantum. If not completed, moved to end of ready queue. Preemptive and fair. Performance depends on quantum size: too small causes overhead, too large becomes FCFS.
Complexity
Time
O(n)
O(n)
O(n)
Space
O(n)
Applications
Industry Use
Time-sharing operating systems (Unix, Linux, Windows)
Interactive multi-user systems
Web server request handling
Real-time systems with equal priority tasks
Educational operating systems
Fair resource allocation in cloud computing
Use Cases
Related Algorithms
First Come First Serve (FCFS)
Non-preemptive scheduling executing processes in arrival order. Simple queue-based scheduling algorithm that serves as the foundation for understanding CPU scheduling. Despite its simplicity, FCFS can suffer from the convoy effect where short processes are delayed by long-running processes ahead of them in the queue.
Shortest Job First (SJF)
Schedules process with shortest burst time first. Minimizes average waiting time (optimal).
Priority Scheduling
Schedules processes based on priority. Higher priority executes first. Can be preemptive or non-preemptive.
Quicksort
A highly efficient, in-place sorting algorithm that uses divide-and-conquer strategy. Invented by Tony Hoare in 1959, it remains one of the most widely used sorting algorithms due to its excellent average-case performance and cache efficiency.