SCAN ALGORITHM

Let's Explore

Image

 

Description of the algorithm:

It is also called as Elevator Algorithm. In this algorithm, the disk arm moves into a particular direction till the end, satisfying all the requests coming in its path,and then it turns backand moves in the reverse direction satisfying requests coming in its path. It works in the way an elevator works, elevator moves in a direction completely till the last floor of that direction and then turns back.

Image

 

Flow of the algorithm:

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

Image

 

Implementation of the algorithm:

Image

 

Output of the algorithm: