# Introduction to Round-Robin Scheduling

## What is Round-Robin Scheduling?

This algorithm takes its name from the round-robin principle, which distributes something equally among all participants. This is the oldest, most straightforward scheduling algorithm used for multitasking. During round-robin scheduling, each ready task runs cyclically for a limited period. As a result of this algorithm, processes also run without starvation.

## The Round Robin Algorithm Working Process

1. A ready queue gets established for all processes.
2. Each process' burst time gets compared to the CPU's time quantum.
3. The Round Robin scheduling algorithm executes the process within the time quantum if the burst time is less than or equal to the time quantum.
4. When a process' burst time exceeds a time quantum, the process gets executed until it reaches the time quantum (TQ).
5. The time quantum expires, and the process checks to see if it has finished.
6. As soon as the process is complete, it terminates. Otherwise, the process returns to the ready state.

## Characteristics of Round Robin Scheduling

Round Robin Scheduling has the following essential characteristics:

• First, a Round Robin algorithm works on a preemptive basis.
• During time quantum/time slice, a fixed interval time allows moving to the following process on the CPU.
• In the queue, the preempted process appears at the end.
• It would be beneficial to have a minimum time slice for each task that needs to get completed. Nevertheless, it may differ from one OS to another.
• This algorithm responds to an event in real time within a given period.

• Considering that it doesn't depend on the burst time, the system can use it.
• It is not affected by starvation or convoy effects.
• CPU resources are made available to all jobs on a fair basis.

• The system's response time increases as the time quantum increases.
• Context switching is more expensive in systems with lower time quantum.
• It is challenging to determine a perfect time quantum in the system.

## Important Terms

• Completion Time: refers to when a process is completed.
• Turn Around Time: represents the difference between completion and arrival times. To calculate the same, use this formula: Turn Around Time = Completion Time â€“ Arrival Time.
• Waiting Time(W.T): It measures the time difference between turnaround time and burst time. As a result, Waiting Time = Turn Around Time â€“ Burst Time

Code Sample

The following code demonstrates how Round Robin Scheduling Algorithm works in Java.

 import java.util.Scanner;public class RoundRobinExample {    public static void main(String args[]) {        int n,x,q_t,count=0,temp,sq=0,b_t[],w_t[],ta_t[],rem_bt[];        float aw_t=0,ata_t=0;        b_t = new int[10];        w_t = new int[10];        ta_t = new int[10];        rem_bt = new int[10];        Scanner sc=new Scanner(System.in);        System.out.print("Number of processes(maximum 10) = ");        n = sc.nextInt();        System.out.print("Enter process burst time\n");        for (x=0; xq_t)                    rem_bt[x]= rem_bt[x] - q_t;                else if(rem_bt[x]>=0) {                    temp = rem_bt[x];                    rem_bt[x] = 0;                }                sq = sq + temp;                ta_t[x] = sq;            }            if(n == count)                break;        }        System.out.print("*********************************************************************************");        System.out.print("\nProcess\t      Burst Time\t       Turnaround Time\t          Waiting Time\n");        System.out.print("*********************************************************************************");        for(x=0; x
write your code here: Coding Playground