Scheduling Algorithms in Operating Systems - Part 5 - Highest Response Ratio next
Published: 2021-12-07 12:41:37

---
title: Scheduling Algorithms in Operating Systems - Part 5 - Highest Response Ratio next
published: true
description: 
tags: 
cover_image: https://cdn-images-1.medium.com/max/2000/1*YFMjCPU7Ttl0xb1lmiUkVg.jpeg
---
#### You can skip the intro if you have been through the [**Part - 1**](https://dev.to/iamdigitalanna/scheduling-algorithms-in-operating-systems-5g7a) or [**Part - 2**](https://dev.to/iamdigitalanna/scheduling-algorithms-in-operating-systems-part-2-shortest-job-first-sjf-4if3) or [**Part - 3**](https://dev.to/iamdigitalanna/scheduling-algorithms-in-operating-systems-part-3-round-robin-algorithm-9j9) or [**Part - 4**](https://dev.to/iamdigitalanna/scheduling-algorithms-in-operating-systems-part-4-priority-scheduling-algorithm-558b) of the series

Like humans, the operating system needs to plan its activities. These activities are the various processes that need to be executed by the OS. The OS needs to schedule all its processes properly to ensure that they get executed without any problems and in minimal time.

For this purpose, there are many scheduling algorithms like the **First Come First Serve** (FCFS) algorithm, **Shortest Job First** (SJF) algorithm, etc. We will be discussing these algorithms in detail but before that, we need to understand some terms.

 1. **Arrival Time**: The time at which the process arrives in the processor for execution.

 2. **Waiting Time**: The time for which a process has to wait before it starts executing. A process may have to wait if some other process is being executed (in a uniprocessor environment) or when the resources required by the process are not available, etc. It is calculated as :
>  *Waiting time = Completion Time- Arrival Time- Service Time*

3. **Service Time/ Burst time**: The time required by the process to complete its execution.

4. **Turnaround Time**: The interval between the time at which the process starts executing and the arrival time of the process. It is calculated using the formula:
>  *Turnaround Time = Service Time + Waiting Time*

Now, let us have a look at the Highest Response Ratio Next algorithm :

## Highest Response Ratio Next Algorithm:

In this, for execution, we select the process that has the highest response ratio.
>  *Response Ratio =( Waiting Time + Service Time ) / Service time*

Let us understand this using an example:

![](https://cdn-images-1.medium.com/max/2710/0*yceYPNq8fQj_i1zl.png)

Here, process A is the only process to enter the processor and hence it starts executing. Meanwhile, B enters the queue.

![](https://cdn-images-1.medium.com/max/2510/0*1cF-aLlWyAsWFSHI.png)

Now, since B is the only process to enter the queue, it starts executing next.

![](https://cdn-images-1.medium.com/max/2510/0*tYsErcG9-Lqc_oWj.png)

Now comes the trickier part.

There are three processes — C, D, E in the queue. How do we decide which one to select out of these?

It's very easy! We calculate the response ratio for each of them using the formula mentioned earlier.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dp35o2lm9b47pooe6bq6.png)

As you can see, C has the highest response ratio. Hence it will be executed next.

![](https://cdn-images-1.medium.com/max/2510/0*0zo47dku3wO0N5xE.png)

Now we have to choose between process D and E. Let us calculate the response ratio for these processes.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dzj5r28ahuazjdbx3ra8.png)

Since E has the highest response ratio, it is executed next.

![](https://cdn-images-1.medium.com/max/2510/0*lmMG-70fn2JCWrtt.png)

Now the only process left is D. Hence, it will be executed finally.

![](https://cdn-images-1.medium.com/max/2510/0*9WXSq-QwLJGS3BbD.png)

Let us now calculate the average waiting time and turnaround time for this example:

![](https://cdn-images-1.medium.com/max/2710/0*dVw_Tb4WBCpdFe8b.png)

This is how processes are scheduled using the Highest Response Ratio algorithm.

Here, the disadvantage is that extra calculation is required. Also, the service time has to be known and the waiting time has to be tracked.

Hope this helps you!

Have a nice day 😊!!

PS : This was the last part of the scheduling algorithms series. Hope all your questions were answered. Still if there's anything you need to ask or add to what I've posted please let me know in the comments.
Thanks!