VOOZH about

URL: https://www.geeksforgeeks.org/dsa/scan-elevator-disk-scheduling-algorithms/

⇱ SCAN (Elevator) Disk Scheduling Algorithms - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

SCAN (Elevator) Disk Scheduling Algorithms

Last Updated : 12 Jul, 2025

In theSCAN Disk Scheduling Algorithm, the head starts from one end of the disk and moves towards the other end, servicing requests in between one by one and reaching the other end. Then the direction of the head is reversed and the process continues as the head continuously scans back and forth to access the disk. In this article, we will look into the SCAN (Elevator) algorithm in detail along with the code, its implementation, etc.

What is SCAN (Elevator) Disk Scheduling Algorithm?

Given an array of disk track numbers and initial head position, our task is to find the total number of seek operations to access all the requested tracks if the SCAN disk scheduling algorithm is used. So, this algorithm works as an elevator and is hence also known as the elevator algorithm. As a result, the requests at the midrange are serviced more and those arriving behind the disk arm will have to wait.

Advantages of SCAN (Elevator) Algorithm

Disadvantages of the SCAN (Elevator) Algorithm 

  • More complex algorithm to implement.
  • This algorithm is not fair because it causes a long waiting time for the cylinders just visited by the head.
  • It causes the head to move till the end of the disk in this way the requests arriving ahead of the arm position would get immediate service but some other requests that arrive behind the arm position will have to wait for the request to complete.

Algorithm

  • Step 1: Let the Request array represent an array storing indexes of tracks that have been requested in ascending order of their time of arrival. β€˜head’ is the position of the disk head.
  • Step 2: Let direction represent whether the head is moving towards left or right.
  • Step 3: In the direction in which the head is moving, service all tracks one by one.
  • Step 4: Calculate the absolute distance of the track from the head.
  • Step 5: Increment the total seek count with this distance.
  • Step 6: The currently serviced track position now becomes the new head position.
  • Step 7: Go to step 3 until we reach one of the ends of the disk.
  • Step 8: If we reach the end of the disk reverse the direction and go to step 2 until all tracks in the request array have not been serviced.

Example:

Input: 
Request sequence = {176, 79, 34, 60, 92, 11, 41, 114}
Initial head position = 50
Direction = left (We are moving from right to left)
Output:
Total number of seek operations = 226
Seek Sequence is
41
34
11
0
60
79
92
114
176

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

πŸ‘ SCAN Disk Scheduling Algorithm
SCAN Disk Scheduling Algorithm

Therefore, the total seek count is calculated as: 

= (50-41) + (41-34) + (34-11) + (11-0) + (60-0) + (79-60) + (92-79) + (114-92) + (176-114)
= 226

Implementation

The implementation of SCAN is given below. Note that distance is used to store the absolute distance between the head and the current track position. disk_size is the size of the disk. Vectors left and right store all the request tracks on the left-hand side and the right-hand side of the initial head position respectively. 

Output

Total number of Seek Operations = 226

Seek Sequence: 41, 34, 11, 0, 60, 79, 92, 114, 176

Time Complexity: O(N * logN)

Auxiliary Space: O(N)

Conclusion

The SCAN disk scheduling algorithm is efficient for reducing seek times in disk management but introduces some complexity in implementation and can be unequal for certain requests. Its elevator like behavior ensures that all requests are eventually serviced, providing a balance between simplicity and efficiency.

Will the SCAN Algorithm consider all pending requests?

The SCAN Algorithm considers all pending requests in one direction before changing the direction.

Is SCAN Preemptive or Non-Preemptive?

SCAN is a non-preemptive disk scheduling algorithm, after starting the requests, it completes them without any interruptions.

What happens if the head reaches the disk end but there are no more requests in that direction?

The head continues until it reaches the end of the disk, even if there are no more requests. It then reverses direction and services any remaining requests in the opposite direction.

Is SCAN a fair scheduling algorithm?

No, SCAN may not be fair to all requests. Tracks located just behind the head will have to wait until the head reverses direction, which may increase their waiting time.

Comment
Article Tags:
Article Tags: