L-6.6: SCAN Algorithm in Disk scheduling with Example | Operating System - YouTube

Channel: Gate Smashers

[0]
Hello friends, welcome to Gate Smashers, the topic is
[2]
SCAN algorithm in disk scheduling
[4]
so here we start from the questions
[6]
and here 200 tracks are already given in the disk
[9]
0 to 199
[10]
and I have the request queue
[12]
these are the request
[13]
which are already present in the queue
[15]
current position is from 50
[17]
and now I am using the algorithm SCAN
[20]
So how does the scan algorithm works?
[22]
Lets start with the
[25]
and here first of all I have 50
[28]
that is the current position of read write head
[30]
and the scan algorithm
[32]
is also called elevator algorithm
[34]
where we have to move in one direction and
[37]
and we have to move till last point in that direction
[41]
so what does this mean?
[42]
So here I have direction in this question, that is
[46]
I think I forgot to write the direction
[47]
direction you can take as lets say direction is towards the larger value
[51]
You have been given like this, Lets say
[53]
direction is towards larger value
[56]
so from 50 we have to move towards larger value
[59]
So if we move from 50 towards larger value
[61]
so which value comes first?
[63]
82
[64]
So I covered 82
[66]
after 82
[67]
which is the next request coming?
[70]
140
[72]
and after 140 next request is
[75]
170
[78]
170
[82]
after 170, the next request I have is
[85]
190
[87]
So I want to say
[88]
that after 50 here
[90]
I have to move towards larger direction
[93]
and while moving towards that direction
[96]
what all the request that have come
[98]
and you handle all those request
[101]
means all the request
[102]
what was it? 82, 140
[104]
170, 190
[107]
so I have handled all these requests
[109]
means I will service all these request
[113]
but this scan algorithm
[116]
is called elevator algorithm because
[118]
it will not go upto 190 only
[120]
but will go upto 199, this means
[123]
so the direction in which you are moving
[125]
you have to move till the last point in that direction
[128]
If you have in the question
[131]
that you have to move from 50 towards the lower value
[135]
so where will you go from 50
[137]
from 50 to 43
[139]
after 43 you move to 24
[141]
after 24 to 16
[144]
and after 16 upto 0
[147]
you have to go in the track number till the very last value.
[151]
so here what is the larger value, which is given in the question
[153]
so we first solve the according to the larger value
[156]
so went to 199
[157]
now up to 199
[159]
we have covered all the values from 50 to 199
[163]
but after 199
[165]
now we are changing direction.
[167]
now which value was less than 50 ? 43
[171]
so I鈥檓 covering 43 over here
[173]
what is the value after 43 ? 24
[176]
so am covering 24
[178]
what is the value after 24 ? 16
[180]
so I am covering 16
[182]
and another point to keep in mind here
[185]
stop here after coming to 16
[188]
now here you do not have to go to zero
[191]
means to say this
[193]
the work of the elevator means
[195]
to go to the last in one direction
[197]
but in the second direction , do not go to the very last
[201]
have to go till the last request
[203]
because after 16
[205]
there is no request in my queue ?
[208]
in these cases, if the request was zero ,
[210]
you would have gone towards it
[212]
whatever was the last request otherwise
[214]
that is 16 , so I moved here and went to 16
[218]
so all you have to do is simply calculate here
[220]
I have already told in earlier videos how to calculate
[223]
in the CFSO and SSTF
[225]
you don't need to calculate one by one
[228]
if you want to do you can also calculate one by one
[230]
otherwise 82-50
[232]
140 - 82 , 170- this and this
[235]
but what is the best make the calculation easy
[238]
199-50
[242]
calculate at once
[243]
(199 - 50) + (199 - 16)
[250]
take out this value directly
[253]
if you will solve it, the answer will come for you 332
[258]
and if the same question is given as
[260]
that your direction is towards the lower value
[263]
so from 50 you have to go to 24 , 16, 0
[267]
after zero you went
[269]
whatever request is on your way now 82 ,140
[273]
what was next is 140
[275]
after 140 you have 170
[278]
the request after 170 is 190
[282]
but now take care, that you don't have to go till 199
[287]
the last value which was the last request has to be reached till that point
[290]
but the direction in which you start ?
[293]
you will have to move in that direction till the very last
[297]
that is how the SCAN Algorithm works
[300]
here somewhere comes a doubt that
[303]
when the last request is 190
[306]
so why am I moving to 199
[308]
because it is working like an elevator
[310]
and let's say I have ten floors
[313]
in one building
[314]
so maybe the last sequence which is till the 9th floor
[317]
but why is she going till the 10th floor ?
[319]
maybe a request comes dynamically at run time
[323]
that me too
[325]
or any other guy who is on floor 10 has pressed the button at run time
[329]
if here I talk about the request
[331]
this request is static
[333]
it is good in static, if it does not goes to 199 then it is Ok
[337]
but if we run it dynamically
[340]
it is possible in real life that when you are moving in this direction
[343]
then after 190
[345]
lets say in case a request came
[347]
for upto 199
[349]
so it is best for you to move up to 199 in advance
[353]
so that you get that advantage
[356]
but there is also a disadvantage in it
[358]
what is the disadvantage?
[360]
The direction in which you are moving
[362]
you went up to last
[364]
and then changed the direction
[367]
Once you changed the direction
[369]
and after that in case a request comes
[372]
dynamically if a request comes now
[374]
the request is 195
[377]
so now you can't go to 195
[380]
because once you have changed the direction
[382]
you have to come up to the last
[386]
after this again you have to go up to 195
[389]
this means that if I am taking the case as static
[393]
and most of the times in exam you will get the static case
[397]
then in that case you don't need to take any tension
[400]
you can solve this simply with this method
[403]
but if we talk dynamically
[405]
so here there may be a problem in the transaction
[409]
but for the time being, its not necessary for you to remember this transaction
[413]
Simply by using SCAN
[415]
how do we find out the number of tracks
[419]
how to find the number of read write movement, that is the most important part
[422]
and there is also one more small point
[425]
If read write head takes 1 Nanosecond to move
[428]
from one track to another track then what is the total time
[431]
means the time to go from one track to another track
[434]
is 1 nanosecond
[436]
so how much time the scan algorithm will take in total
[439]
So what you have to do, first of all we will find out
[441]
we are doing 332 movement
[444]
means how much total movement the read write head is making
[447]
332, to service all these
[450]
to cover all these
[452]
so obviously, 332 x 1 NS
[455]
that is 332 nanosecond
[458]
which you can calculate easily
[460]
This question is asked many times in extension
[463]
The same questions is in FFCF and FCFS
[467]
you can follow there too
[469]
So this is all about the scan algorithm, Thank you!