# Which Data Structure Is Used in Round Robin Scheduling?

//

Larry Thompson

Round Robin Scheduling is a popular CPU scheduling algorithm used in operating systems. It is designed to provide fairness by dividing CPU time equally among all processes in the system. One key aspect of Round Robin Scheduling is the use of a particular data structure – the circular queue.

## What is a Circular Queue?

A circular queue, also known as a ring buffer, is a data structure that represents a fixed-size collection of elements. It has two pointers, front and rear, which indicate the current positions of the first and last elements in the queue, respectively.

The circular queue differs from a regular queue in that it wraps around when it reaches the end. This means that if the rear pointer reaches the end of the queue, it will wrap around to the beginning, effectively creating a circular structure.

## Why Use a Circular Queue in Round Robin Scheduling?

In Round Robin Scheduling, each process is assigned a fixed time slot called a time quantum. The idea is to give each process an equal amount of CPU time before moving on to the next process.

A circular queue is an ideal data structure for implementing this algorithm because:

• Efficient Time Complexity: The circular nature of the queue allows for constant-time access to both ends (front and rear). This ensures that enqueueing and dequeueing operations can be performed efficiently.
• Fairness: By using a circular queue, every process gets an equal chance to execute within its time quantum. The algorithm simply moves on to the next process once its time quantum expires.
• Easy Implementation: The circular queue’s concept aligns well with the round-robin nature of the scheduling algorithm, making it straightforward to implement.

## How Round Robin Scheduling Works with a Circular Queue

To illustrate how Round Robin Scheduling works with a circular queue, let’s consider an example:

Suppose we have three processes: P1, P2, and P3, each with a time quantum of 4 units. We initialize an empty circular queue and enqueue the processes in the order they arrive.

The circular queue would look as follows:

• P1 -> P2 -> P3

Initially, the front and rear pointers both point to P1. The CPU executes P1 for 4 units and then moves on to the next process in the circular queue.

After one time quantum:

• P1 -> P2 -> P3

The front pointer has moved to P2 while the rear pointer remains at P1. The CPU executes P2 for 4 units before moving on again.

After two time quanta:

• P1 -> P2 -> P3

This time, both the front and rear pointers have moved. The CPU executes P3 for 4 units before wrapping around to the beginning of the circular queue.

After three time quanta:

• P1 -> P2 -> P3

In this manner, Round Robin Scheduling continues until all processes have completed their execution.

## Conclusion

The circular queue is a fundamental data structure used in Round Robin Scheduling. Its circular nature allows for efficient and fair allocation of CPU time to each process. By understanding the underlying data structure, we gain insight into how the scheduling algorithm operates.

Next time you encounter Round Robin Scheduling, remember the role of the circular queue and how it contributes to the overall fairness and efficiency of the system.