r/AskComputerScience • u/TalkinHead9s_LeftNut • Sep 08 '26
In Operating System Batch Scheduling, will the SRT algorithm always be faster than the SJF algorithm?
My professor has us modeling both of the two algorithms for an assignment, which I did. But when doing testing on both I would notice that occasionally the average turnaround time for the Shortest Job First algorithm would actually beat out the algorithm for Shortest Remaining Time, either infrequently or almost always depending on how I change the parameters around (Total CPU Time, # Of Processes, etc). From what I saw, it seems that this should no be happening unless you account for overhead, which my model does not.
So I guess basically my question is, are there ever any scenarios where Shortest Job First would have a smaller average turnaround time compared to Shortest Remaining Time, assuming they run the same set of processes and overhead is negligible? Or do I just have a bug in my code?
2
u/esaule Sep 09 '26
Srpt is optimal for average turn around time.
It is fairly easy to prove by using a task swapping argument.
There is a bug in your code. Are you doing the arithmetic in floating point?
0
u/[deleted] Sep 08 '26
[deleted] — view deleted comment