Shortest Job First Algorithm considers length of each job,
in the ready queue, and executes the jobs, which is shorter
in length, first.
When 3 jobs are submitted to the system for execution, the
CPU looks out for the job with shortest CPU burst and executes
it first.
However, when two jobs having the same CPU burst, arrive at
the ready queue, the pickup mode will be changed to FCFS.
Suppose the ready queue contains,
Job Burst time
1 24
2 3
3 3
Then, the system will re-arrange the ready queue as per shortest
job first algorithm. Here, in the above example, job-2 and
job-2 are having the equal CPU burst. So, in this case, FCFS
is used to rearrange the two jobs. Since, job-2 arrived before
job-3 arrived, job-2 will be executed first, then the job-3
will be considered. Job-1 will hit the bottom of ready queue
because it has got highest CPU burst.
Now, the ready queue will look as,
Job–2 Job-3 Job-1
3 3
24
Now, the average turnaround time according to SJF algorithm
will be
3 + 6 + 24 / 3 = 13.
Comparing to FCFS, this average turnaround time will be less,
when we take systems implementing SJF Algorithm. The real
complexity of this algorithm lies in knowing the length of
next CPU burst.
In the system, which is making use of this algorithm, program
developers are motivated to estimate the job’s time
accurately. We may not know the length of the next CPU burst
but we may be able to predict its value.