SCAN algorithm : - it starts from given position and moves till the end and then changes its direction and starts moving towards the other end and keeps doing it until all requests are processed.
5,17,16,125,28,170,8,32.
first write the given request in ascending order and also add the position where the disk head is currently present(35), starting and ending of disk.
0, 5 , 8 , 16 , 17 , 28 , 32 , 35 ,125 , 170 , 199.
start from the current head location and move in the direction mentioned in the question(moving towards higher cylinder number)
35 -> 125 -> 170 -> 199.
now head came to the end so it changes its direction and processes the remaining disk request.
199 -> 32 -> 28 -> 17 -> 16 -> 8 -> 5.
since 5 is the last disk request we don't need to move further.
so head in SCAN algo is moving like
35 -> 125 -> 170 -> 199 -> 32 -> 28 -> 17 -> 16 -> 8 -> 5.
calculate difference between each consecutive digits.
|125 - 35| = 90
|125 - 170| = 45
|170-199| = 29
|199 -32 | = 167
|32 - 28 | =4
|28 -17| = 11
| 17-16 | =1
| 16 -8 | =8
| 5 -8 | =3.
add the difference
90+45+29+167+4+11+1+8+3 = 358 .....this is the total number of head movements required.