VOOZH about

URL: https://www.geeksforgeeks.org/dsa/priority-cpu-scheduling-with-different-arrival-time-set-2/

⇱ Priority CPU Scheduling with different arrival time - Set 2 - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Priority CPU Scheduling with different arrival time - Set 2

Last Updated : 28 Dec, 2024

Prerequisite -Program for Priority Scheduling - Set 1
Priority scheduling is a non-preemptive algorithm and one of the most common scheduling algorithms in batch systems. Each process is assigned first arrival time (less arrival time process first) if two processes have same arrival time, then compare to priorities (highest process first). Also, if two processes have same priority then compare to process number (less process number first). This process is repeated while all process get executed.

Implementation -

  1. First input the processes with their arrival time, burst time and priority.
  2. First process will schedule, which have the lowest arrival time, if two or more processes will have lowest arrival time, then whoever has higher priority will schedule first.
  3. Now further processes will be schedule according to the arrival time and priority of the process. (Here we are assuming that lower the priority number having higher priority). If two process priority are same then sort according to process number.
    Note: In the question, They will clearly mention, which number will have higher priority and which number will have lower priority.
  4. Once all the processes have been arrived, we can schedule them based on their priority.

👁 Image

Gantt Chart - 

👁 Image

Examples -

Input :
process no-> 1 2 3 4 5
arrival time-> 0 1 3 2 4
burst time-> 3 6 1 2 4
priority-> 3 4 9 7 8
Output :
Process_no arrival_time Burst_time Complete_time Turn_Around_Time Waiting_Time
1 0 3 3 3 0
2 1 6 9 8 2
3 3 1 16 13 12
4 2 2 11 9 7
5 4 4 15 11 7
Average Waiting Time is : 5.6
Average Turn Around time is : 8.8

Output: 

Process_no Start_time Complete_time Turn_Around_Time Waiting_Time
1 1 4 3 0
2 5 10 8 3
3 4 5 2 1
4 10 17 13 6
5 17 21 16 12
Average Waiting Time is : 4.4
Average Turn Around time is : 8.4

Time Complexity: O(N * logN), where N is the total number of processes. 
Auxiliary Space: O(N) 


Comment
Article Tags:
Article Tags: