![]() |
VOOZH | about |
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.
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.
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.
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)
= 226The 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.
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)
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.