Shortest Job First Scheduling Algorithm

For Complete YouTube Video: Click Here

In this class, we will try to understand Shortest Job First Scheduling Algorithm.

We have already made a detailed explanation of “First Come First Serve FCFS” in our previous classes.

Shortest Job First Scheduling Algorithm

The Shortest Job First Scheduling Algorithm will execute the process with the shortest execution time.

The shortest execution time means the shortest burst time.

The shortest job first is a non-preemptive algorithm.

To understand this, we will consider the example shown below.

The values in the above example are the same as those in the FCFS.

Let us consider the Gantt chart for analysis.

The first process in the ready state is P1, as it is the only process in the ready state we will that for execution.

Because this is a non-preemptive algorithm, P1 will get executed for its burst time.

After two units in time, the process P2 and P3 have arrived.

Now, we have the choice to select one among them.

We will select the process with the shortest burst time.

In our case, P3 will be selected and executed for its burst time.

The processes P1 and P3 are executed.

After three units of time, we have P2 and P4 in the ready state.

Among those two, P4 with the shortest burst time will get executed.

We are left with P2 and P5 processes in the ready state.

P5 with the burst time will be executed first, then P2 will get completed.

The final Gantt Chart of all the processes is shown below.

Using the Gantt Chart, we will find the completion times of all the processes.

The turnaround time for all the processes is the difference between the Completion time and Arrival time.

Similarly, the waiting time is the difference between the Turn Around Time and Burst Time.

The image below is the complete table with all the values.

In comparison with FCFS the shortest job first has less average waiting time.

For the above example in case of FCFS it has an average waiting time of 3.1 and for SJF it is 2.1.

Practically it is impossible to implement SJF because we can’t predict the burst times a head of execution.