1. All the processes will have different arrival times.
2. In the FCFS scheduling algorithm, processes that come first ( i.e have lesser arrival time) will be executed first.
3. Turn around time of a Process is the time difference between arrival time and the time at which the process completed.
4. The waiting time of a process is the total time, the process is waiting, i.e. difference between turnaround time and burst time.
5. Completion time is the time at which a process completes.
Let there be 4 Processes with the following arrival time and burst time.
Wait time, turnaround, and completion time for each process are:
The first line of input contains an integer ‘T’ denoting the number of test cases. The description of ‘T’ test cases follows
The first line of each test case contains an integer ‘N’ representing the number of processes.
The second line of each test case contains ‘N’ space-separated integers, where ‘i-th’ integer represents the arrival time for the ‘i-th’ processes.
The last line of the test cases contains ‘N’ space-separated integers, where ‘i-th’ integer represents the burst time for the ‘i-th’ processes.
For each test case, print four lines.
In the first line, print ‘N’ space-separated integers, where ‘i-th’ integer represents the waiting time of the ‘i-th’ process.
In the second line of each test case, print ‘N’ space-separated integers, where ‘i -th’ integer represents the turnaround time of ‘i-th’ process.
In the third line of each test case, print ‘N’ space-separated integers, where ‘i -th’ integer represents the completion time of ‘i-th’ process.
In the last line print two space-separated integers, representing the floor value of average waiting time and the average turnaround time respectively.
The output of each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 5000
0 <= arrival[i], burst[i] <= 10 ^ 9
Where ‘T’ is the total number of test cases, ‘N’ is the number of processes, and ‘arrival[i]’, ‘burst[i]’ represents the arrival time and burst time of the ‘i-th’ processes.
Time Limit: 1 sec
Approach: As the CPU scheduling algorithm is First Come First Serve, So the process with minimum arrival time will be executed first, when this process is completely executed, then only the next process with minimum arrival time will start executing.
Turn around time of a process is the time span from its arrival to its completion. For example, if a process arrives at 5 unit time and it completes at 10 unit time, then its turnaround time will be (10 - 5) units.
The waiting time of a process is the time span from its arrival to the stage when this process starts executing. When a process starts executing immediately then its arrival time will be 0.
To Calculate waiting time and turnaround time for all the processes, we iterate over all processes in ascending order with respect to their arrival time, and then find their start time i.e time when they start executing, completion time i.e. time when the process gets completed. From these, we can easily calculate their turnaround time and wait time by the below formula.
Start time = max (arrival time of current process, completion time of the previous process)
Completion time = start time + burst time of the current process.
Turnaround time = completion time - arrival time of the current process.
Waiting time = Turnaround time - burst time of the current process.
Finally, we can calculate the average waiting time by summing all waiting times of all given processes and divide it by total process. Similarly, the average turnaround time will be the summation of the turnaround time of all the processes divided by a total number of processes.
Median Marks
Beautiful Distribution
Max Prefix
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Sort 0s, 1s, 2s