VOOZH about

URL: https://www.geeksforgeeks.org/operating-systems/program-for-sstf-disk-scheduling-algorithm/

⇱ Program for SSTF Disk Scheduling Algorithm - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program for SSTF Disk Scheduling Algorithm

Last Updated : 9 May, 2026

Given an array of disk track numbers and initial head position, our task is to find the total number of seek operations done to access all the requested tracks if Shortest Seek Time First (SSTF) is a disk scheduling algorithm is used.

The basic idea is the tracks that are closer to the current disk head position should be serviced first in order to minimize the seek operations is basically known as Shortest Seek Time First (SSTF).

Algorithm

Step 1: Let the Request array represents an array storing indexes of tracks that have been requested. 'head' is the position of the disk head.

Step 2: Find the positive distance of all tracks in the request array from the head.

Step 3: Find a track from the requested array which has not been accessed/serviced yet and has a minimum distance from the head.

Step 4: Increment the total seek count with this distance.

Step 5: Currently serviced track position now becomes the new head position.

Step 6: Go to step 2 until all tracks in the request array have not been serviced. 

Example:

Request sequence = {176, 79, 34, 60, 92, 11, 41, 114} 
Initial head position = 50 

The following chart shows the sequence in which requested tracks are serviced using SSTF.

Therefore, the total seek count is calculated as: 

👁 SSTF (Shortest Seek Time First)
SSTF (Shortest Seek Time First)
= (50-41)+(41-34)+(34-11)+(60-11)+(79-60)+(92-79)+(114-92)+(176-114)
= 204
which can also be directly calculated as: (50-11) + (176-11)

Implementation

The implementation of SSTF is given below. Note that we have made a node class having 2 members. ‘distance’ is used to store the distance between the head and the track position. ‘accessed’ is a boolean variable that tells whether the track has been accessed/serviced before by the disk head or not. 

Output

Total number of seek operations = 204
Seek Sequence: 50, 41, 34, 11, 60, 79, 92, 114, 176 

Time Complexity: O(N^2)

Auxiliary Space: O(N) 

Advantages of Shortest Seek Time First (SSTF)

  • Better performance than the FCFS scheduling algorithm.
  • It provides better throughput.
  • This algorithm is used in Batch Processing systems where throughput is more important.
  • It has a less average response and waiting time.

Disadvantages of Shortest Seek Time First (SSTF)

  • Starvation is possible for some requests as it favors easy-to-reach requests and ignores the far-away processes.
  • There is a lack of predictability because of the high variance of response time.
  • Switching direction slows things down.
Comment
Article Tags: