**Prerequisite –** CPU Scheduling, SJF – Set 1 (Non- preemptive), Set 2 (Preemptive)

**Shortest Job First (SJF) ** is an optimal scheduling algorithm as it gives maximum Throughput and minimum average waiting time(WT) and turn around time (TAT) but it is not practically implementable because Burst-Time of a process can’t be predicted in advance.

We may not know the length of the next CPU burst, but we may be able to predict its value. We expect the next CPU burst will be similar in length to the previous ones. By computing an approximation of the length of the next CPU burst, we can pick the process with the shortest predicted CPU burst.

There are two methods by which we can predict the burst time of the process :

**1. Static method –** We can predict the Burst-Time by two factors :

**Process size –**

Let say we have Process P_{old}having size 200 KB which is already executed and its Burst-time is 20 Units of time, now lets say we have a New Process P_{new}having size 201 KB which is yet to be executed.

We take Burst-Time of already executed process P_{old}which is almost of same size as that of New process as Burst-Time of New Process P_{new}.**Process type –**

We can predict Burst-Time depending on the Type of Process. Operating System process(like scheduler, dispatcher, segmentation, fragmentation) are faster than User process( Gaming, application softwares ). Burst-Time for any New O.S process can be predicted from any old O.S process of similar type and same for User process.**Simple average –**Given n processes ( P_{1}, P_{2}… P_{n})Τ

_{n+1}= 1/n(Σ^{i=1 to n}t_{i})**Exponential average (Aging) –**Τ

_{n+1}= αt_{n}+ (1 - α)Τ_{n}where α = is smoothing factor and 0 <= α <= 1 ,

t

_{n}= actual burst time of n^{th}process,

Τ_{n}= predicted burst time of n^{th}process.General term,

αt

_{n}+ (1 - α)αt_{n-1}+ (1 - α)^{2}αt_{n-2}...+ (1 - α)^{j}αt_{n-j}...+ (1 - α)^{n+1}Τ_{0}**Τ**is a constant or overall system average._{0}- If α = 0, Τ
^{n+1}= Τ^{n}i.e. no change in value of initial predicted burst time. - If α = 1, Τ
^{n+1}= t^{n}i.e. predicted Burst-Time of new process will always change according to actual Burst-time of n^{th}process. - If α = 1/2, recent and past history are equally weighted.
- Difference between Priority scheduling and Shortest Job First (SJF) CPU scheduling
- Difference between Arrival Time and Burst Time in CPU Scheduling
- Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non- preemptive)
- Shortest Job First (or SJF) CPU Scheduling Non-preemptive algorithm using Segment Tree
- Difference between First Come First Served (FCFS) and Longest Job First (LJF) CPU scheduling algorithms
- Longest Job First (LJF) CPU scheduling algorithm
- Program for Shortest Job First (SJF) scheduling | Set 2 (Preemptive)
- Difference between Shortest Job First (SJF) and Round-Robin (RR) scheduling algorithms
- Difference between Multi Level Queue Scheduling (MLQ) and Shortest Job First
- Difference between Turn Around Time (TAT) and Waiting Time (WT) in CPU Scheduling
- Longest Remaining Time First (LRTF) CPU Scheduling Algorithm
- Longest Remaining Time First (LRTF) CPU Scheduling Program
- First Come, First Serve – CPU Scheduling | (Non-preemptive)
- Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling
- Difference between Priority Scheduling and Round Robin (RR) CPU scheduling
- Priority CPU Scheduling with different arrival time - Set 2
- Time Slicing in CPU scheduling
- Earliest Deadline First (EDF) CPU scheduling algorithm
- Implementation of Non-Preemptive Shortest Job First using Priority Queue
- Clairvoyant Shortest Job first (SJF)

**Note –** Static method for burst time prediction is not reliable as it is always not predicted correctly.

**2. Dynamic method –** Let t_{i} be the actual Burst-Time of i^{th} process and Τ_{n+1} be the predicted Burst-time for n+1^{th} process.

**Smoothening factor (α) –** It controls the relative weight of recent and past history in our prediction.

**Example –**

Calculate the exponential averaging with T1 = 10, α = 0.5 and the algorithm is SJF with previous runs as 8, 7, 4, 16.

(a) 9

(b) 8

(c) 7.5

(d) None

**Explanation :**

Initially T1 = 10 and α = 0.5 and the run times given are 8, 7, 4, 16 as it is shortest job first,

So the possible order in which these processes would serve will be 4, 7, 8, 16 since SJF is a non-preemptive technique.

So, using formula: T2 = α*t1 + (1-α)T1

so we have,

T2 = 0.5*4 + 0.5*10 = 7, here t1 = 4 and T1 = 10

T3 = 0.5*7 + 0.5*7 = 7, here t2 = 7 and T2 = 7

T4 = 0.5*8 + 0.5*7 = 7.5, here t3 = 8 and T3 = 7

So the future prediction for 4th process will be T4 = 7.5 which is the option(c).

This article is contributed by **Yash Singla**. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.