LAST IN FIRST OUT ALGORITHM

Let's Explore

Image

 

Description of the algorithm:

In LIFO (Last In, First Out) algorithm, newest jobs are serviced before the existing ones i.e. in order of requests that get serviced the job that is newest or last entered is serviced first and then the rest in the same order.

Image

 

Flow of the algorithm:

  1. Let Request array represents an array storing indexes of tracks that have been requested in descending order of their time of arrival. ‘head’ is the position of disk head.
  2. Let us one by one take the tracks in default order and calculate the absolute distance of the track from the head.
  3. Increment the total seek count with this distance.
  4. Currently serviced track position now becomes the new head position.
  5. Go to step 2 until all tracks in request array have not been serviced.

Image

 

Implementation of the algorithm:

Image

 

Output of the algorithm: