Implementation of Round Robin CPU Scheduling algorithm using C++ (2024)

  • Home
  • DS & Algo. ▾
    • Data Structure
    • Algorithms
    • Coding Problems
  • Languages ▾
    • C
    • C++
    • C++ STL
    • Java
    • Python
    • Scala
    • Ruby
    • C#.Net
    • Golang
    • Android
    • Kotlin
    • SQL
  • Web. ▾
    • JavaScript
    • CSS
    • jQuery
    • PHP
    • Node.Js
    • AdonisJs
    • VueJS
    • Ajax
    • HTML
    • Django
  • Programs ▾
    • C
    • C++
    • Data Structure
    • Java
    • C#.Net
    • VB.Net
    • Python
    • PHP
    • Golang
    • Scala
    • Swift
    • Rust
    • Ruby
    • Kotlin
    • C Interview Programs
  • Aptitude ▾
    • C Aptitude
    • C++ Aptitude
    • Java Aptitude
    • C# Aptitude
    • PHP Aptitude
    • Linux Aptitude
    • DBMS Aptitude
    • Networking Aptitude
    • AI Aptitude
    • More...
  • Interview ▾
    • Golang
    • MIS Executive
    • DBMS
    • C
    • Embedded C
    • Java
    • SEO
    • HR
  • Find Output ▾
    • C
    • C++
    • C#.Net
    • Java
    • Go
    • PHP
    • More...
  • MCQs ▾
    • Web Technologie MCQs
    • CS Subjects MCQs
    • Databases MCQs
    • Programming MCQs
    • Testing Software MCQs
    • Digital Mktg Subjects MCQs
    • Cloud Computing S/W MCQs
    • Engineering Subjects MCQs
    • Commerce MCQs
    • More MCQs...
  • CS Subjects ▾
    • Machine Learning/AI
    • Operating System
    • Computer Network
    • Software Engineering
    • Discrete Mathematics
    • Digital Electronics
    • Data Mining
    • MIS
    • DBMS
    • Embedded Systems
    • Cryptography
    • CS Fundamental
    • More Tutorials...
  • More ▾
    • Tech Articles
    • Puzzles
    • Full Forms
    • Code Examples
    • Blogs
    • Guest Post
    • Programmer's Calculator
    • XML Sitemap Generator
    • About
    • Contact

Home »Algorithms

In this article, we are going to implement of Round Robin CPU Scheduling Algorithm (which is a preemptive version of FCFS algorithm) using C++ program.
Submitted by Aleesha Ali, on February 06, 2018

This algorithm is the preemptive version of FCFS algorithm.

Preemptive: If a process of higher priority comes then first CPU will be assign to the Process with higher priority first.

Scheduling criteria tells us that any algorithm is how much efficient, the main criteria of scheduling are given below:

  • Arrival time
  • Turnaround time
  • Waiting time
  • Burst time
  • Quantum time

* Ready Queue is a queue where all the processes wait to get CPU for its execution.

Arrival time: The time at which the process enters into ready queue.

Turnaround time: The interval between the times of submission of a process to the time of completion.

Waiting time: The total amount of the time a process spends in ready queue.

Burst time: The time needed by CPU to complete its execution.

Quantum time: The amount of the time a CPU is assign to be executed is known as the quantum time independent of the actual burst time, a process will get scheduled in quantum parts values or we can say in quantum chunks.

Round Robin Algorithm

This algorithm is known as preemptive version of FCFS as discussed earlier, it executes the process on the basis of first come first serve, and the only difference here is it works on the principle of quantum time.

C++ Program for the Round Robin Scheduling

//C++ Program to implement Round Robin //Scheduling CPU Algorithm#include <iostream>#include <vector>/*at = Arrival time,bt = Burst time,time_quantum= Quantum timetat = Turn around time,wt = Waiting time*/using namespace std;int main(){int i,n,time,remain,temps=0,time_quantum;int wt=0,tat=0;cout<<"Enter the total number of process="<<endl;cin>>n;remain=n;// assigning the number of process to remain variablevector<int>at(n);vector<int>bt(n);vector<int>rt(n);//dynamic array declaration using vector method of (STL)//STL standard template library of C++cout<<"Enter the Arrival time, Burst time for All the processes"<<endl;for(i=0;i<n;i++){cin>>at[i];cin>>bt[i];rt[i]=bt[i];}cout<<"Enter the value of time QUANTUM:"<<endl;cin>>time_quantum;cout<<"\n\nProcess\t:Turnaround Time:Waiting Time\n\n";for(time=0,i=0;remain!=0;){if(rt[i]<=time_quantum && rt[i]>0){time += rt[i];//Addition using shorthand operatorsrt[i]=0;temps=1;}else if(rt[i]>0){rt[i] -= time_quantum;//Subtraction using shorthand operatorstime += time_quantum;//Addition using shorthand operators}if(rt[i]==0 && temps==1){remain--;//Desplaying the result of wating, turn around time:printf("Process{%d}\t:\t%d\t:\t%d\n",i+1,time-at[i],time-at[i]-bt[i]);cout<<endl;wt += time-at[i]-bt[i];tat += time-at[i];temps=0;}if(i == n-1)i=0;else if(at[i+1] <= time)i++;elsei=0;}cout<<"Average waiting time "<<wt*1.0/n<<endl;cout<<"Average turn around time "<<tat*1.0/n<<endl;;return 0;}

Output

Implementation of Round Robin CPU Scheduling algorithm using C++ (4)

Related Tutorials

  • Introduction to Algorithms
  • Introduction to Greedy Strategy in Algorithms
  • Stability in sorting
  • External Merge Sorting Algorithm
  • Radix Sort and its Algorithm
  • Bucket Sort Algorithm
  • Bubble sort Algorithm, Flow Chart and C++ Code
  • Insertion sort Algorithm, flowchart and C, C++ Code
  • Merge Sort | One of the best sorting algorithms used for large inputs
  • Binary Search in C, C++
  • Randomized Binary Search
  • Meta Binary Search | One-sided Binary Search
  • Difference between Linear Search and Binary Search
  • Binary Search in String
  • Variants of Binary Search
  • Sieve of Eratosthenes to find prime numbers
  • Optimal Merge Pattern (Algorithm and Example)
  • Given an array of n numbers, Check whether there is any duplicate or not
  • Finding the missing number
  • Find the number occurring an odd number of times
  • Find the pair whose sum is closest to zero in minimum time complexity
  • Find three elements in an array such that their sum is equal to given element K
  • Bitonic Search Algorithm
  • Check whether a number is Fibonacci or not
  • Segregate even and odd numbers in minimum time complexity
  • Find trailing zeros in factorial of a number
  • Find Nearest Greatest Neighbours of each element in an array
  • Interpolation search algorithm
  • Floor and ceil of an element in an array using C++
  • Two Elements whose sum is closest to zero
  • Find a pair with a given difference
  • Count number of occurrences (or frequency) in a sorted array
  • Find a Fixed Point (Value equal to index) in a given array
  • Find the maximum element in an array which is first increasing and then decreasing
  • Dynamic Programming (Components, Applications and Elements)
  • Algorithm for fractional knapsack problem
  • Algorithm and procedure to solve a longest common subsequence problem
  • Find the Nth Fibonacci number | C++
  • Longest Common Subsequence using Dynamic programming (DP)
  • Longest Increasing Subsequence using Dynamic programming (DP)
  • Find the maximum sub-array sum using KADANE'S ALGORITHM
  • Non-intersecting chords using Dynamic Programming (DP)
  • Edit Distance using Dynamic Programming (DP)
  • Finding Ugly Number using Dynamic Programming (DP)
  • Egg dropping problem using Dynamic Programming (DP)
  • Wild card matching problem using Dynamic programming (DP)
  • Compute sum of digits in all numbers from 1 to N for a given N
  • Minimum jumps required using Dynamic programming (DP)
  • Graph coloring problem's solution using backtracking algorithm
  • Breadth First Search (BFS) and Depth First Search (DFS) Algorithms
  • Travelling Salesman Problem
  • Kruskal's (P) and Prim's (K) Algorithms
  • Multistage graph problem with forward approach and backward approach algorithms
  • Floyd Warshall algorithm with its Pseudo Code
  • Backtracking (Types and Algorithms)
  • 4 Queen's problem and solution using backtracking algorithm
  • N Queen's problem and solution using backtracking algorithm
  • Find the GCD (Greatest Common Divisor) of two numbers using EUCLID'S ALGORITHM
  • Compute the value of A raise to the power B using Fast Exponentiation
  • Implement First Come First Served (FCFS) CPU Scheduling Algorithm using C program
  • Implementations of FCFS scheduling algorithm using C++
  • Implementation of Shortest Job First (SJF) Non-Preemptive CPU scheduling algorithm using C++
  • Implementation of Shortest Job First (SJF) Preemptive CPU scheduling algorithm using C++
  • Implementation of Priority scheduling (Pre-emptive) algorithm using C++
  • Implementation of Priority scheduling (Non Pre-emptive) algorithm using C++
  • Implementation of Round Robin CPU Scheduling algorithm using C++
  • Analysis of LRU page replacement algorithm and Belady's anomaly
  • Branch and Bound
  • Find the roots of a complex polynomial equation using Regula Falsi Method in C
  • Divide and Conquer Paradigm (What it is, Its Applications, Pros and Cons)
  • Jump Search Implementation using C++
  • Optimal Merge Pattern (Algorithm and Example)
  • Introduction to Greedy Strategy in Algorithms
  • Strassen's Matrix Multiplication in algorithms
  • Huffman Coding (Algorithm, Example and Time complexity)
  • Backtracking (Types and Algorithms)
  • 4 Queen's problem and solution using backtracking algorithm
  • N Queen's problem and solution using backtracking algorithm
  • Graph coloring problem's solution using backtracking algorithm
  • Tournament Tree and their properties
  • Deterministic and Non Deterministic Algorithms
  • Lower Bound Theory
  • Non Recursive Tree Traversal Algorithm
  • Line Drawing Algorithm
  • Breadth First Search (BFS) and Depth First Search (DFS) Algorithms
  • P and NP problems and solutions | Algorithms
  • Travelling Salesman Problem
  • 2 – 3 Trees Algorithm
  • Algorithm and procedure to solve a longest common subsequence problem
  • Midpoint Circle Algorithm
  • Reliability design problem
  • Removing consecutive duplicates from a string
  • Fast Exponentiation using Bitmasking

Comments and Discussions!

Load comments ↻


Implementation of Round Robin CPU Scheduling algorithm using C++ (2024)
Top Articles
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 6312

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.