Exercises — Disk scheduling — FCFS, SCAN, C-SCAN, LOOK
4.2.38 · D4· Coding › Operating Systems › Disk scheduling — FCFS, SCAN, C-SCAN, LOOK
Pehle block of problems ke liye jo number line use hogi uska ek quick reminder:

Level 1 — Recognition
Exercise 1.1 (L1)
Har description ke liye algorithm ka naam batao: FCFS, SCAN, C-SCAN, ya LOOK.
(a) "Requests ko strictly usi order mein serve karo jisme wo aaye." (b) "Ek direction mein sweep karo, physical edge (0 ya max) tak jao, reverse karo, baaki serve karo." (c) "Ek direction mein sirf last request tak sweep karo, phir reverse karo — physical edge kabhi touch mat karo." (d) "Ek direction mein sweep karo, bina serve kiye far extreme par jump karo, wahi direction mein phir sweep karo."
Recall Solution 1.1
(a) FCFS — bilkul koi reordering nahi. (b) SCAN — wo elevator jo wall se takraata hai. (c) LOOK — yeh sirf last request tak "peek" karta hai. (d) C-SCAN — one-way circular escalator.
Kyun: in sabko sirf yeh teen cheezein alag karti hain: (i) kya reorder karte hain, (ii) kya physical boundary touch karte hain, aur (iii) kya return trip par serve karte hain. Yeh triple poori family ko fully classify kar deta hai.
Exercise 1.2 (L1)
Head cylinder 50 par hai aur next request cylinder 90 hai. Is single move ki cost kitne cylinders ki hogi?
Recall Solution 1.2
Ek move ki cost hai cylinders. Yeh literally formula ke sum ka ek term hai — kuch nahi iske ilawa.
Level 2 — Application
Is poore level ke liye standard setup: Queue (arrival order): 82, 170, 43, 140, 24, 16, 190 Head start . Disk range: 0–199. Direction: pehle up (bade cylinders ki taraf). Reference ke liye sorted: 16, 24, 43, 82, 140, 170, 190.
Exercise 2.1 (L2) — FCFS
FCFS ke under total head movement compute karo.
Recall Solution 2.1
KYA: queue ko arrival order mein walk karo, koi sorting nahi. Order: . Bade numbers kyun: aur jumps mein head poori disk cross karta hai — yeh FCFS ki signature waste hai.
Exercise 2.2 (L2) — SCAN
SCAN (up first, disk end = 199) ke under total head movement compute karo.
Recall Solution 2.2
KYA: upar jaao sabko serve karo, 199 touch karo, reverse lo, baaki neeche serve karo. Up path: . Down path: . Up movement: . Down movement: . 199 implicitly do baar kyun aata hai: hum 199 tak travel karte hain (149 ka hissa) aur 199 se travel karte hain (183 ka hissa). SCAN wall tak poora trip pay karta hai chahe 199 par koi request na ho.
Exercise 2.3 (L2) — LOOK
Same setup, LOOK ke under.
Recall Solution 2.3
KYA: identical order, lekin last actual up-request (190) par ruko, 199 kabhi mat jao. Up: . Down: . Up movement: . Down movement: . SCAN se check karo: SCAN ki extra cost hai, aur indeed . ✔
Level 3 — Analysis
Is level ke liye setup: Queue: 98, 183, 37, 122, 14, 124, 65, 67 · Head: 53 · Range: 0–199. (Yeh parent note ka standard example hai — khud check karne ke liye iske known answers reuse karo.)
Exercise 3.1 (L3) — Direction matters
Parent ne SCAN up-first = 331 compute kiya. Ab SCAN down-first compute karo (head pehle cylinder 0 ki taraf move karta hai, 0 touch karta hai, phir upar reverse karta hai). Yahan kaun sa direction sasta hai, aur kyun?
Recall Solution 3.1
Sorted: 14, 37, 65, 67, 98, 122, 124, 183. Down first: , phir upar: . Down movement: . Up movement: . Compare: up-first SCAN , down-first SCAN . Down-first se sasta hai. KYun: head 53 par bottom edge (0) ke bahut paas hai, top edge (199) se nahi. Paas wali wall ki taraf pehle jaane par boundary reach karne mein bahut kam waste hoti hai. Direction cosmetic nahi hai — yeh answer ko ~30% tak swing kar sakta hai.
Exercise 3.2 (L3) — C-SCAN with vs without the wrap counted
C-SCAN (up first) do taron se compute karo: (a) wrap-around jump count karke, (b) wrap ignore karke (kuch textbooks aisa karte hain). Dono totals batao.
Recall Solution 3.2
Up: , phir jump , phir upar: .
- End tak upar: .
- Wrap jump: .
- Last tak resume up: .
(a) Wrap ke saath: . (b) Wrap ke bina: . Ambiguity kyun: wrap ek real physical head movement hai, isliye usse count karna (382) honest total-travel number hai. Lekin kuch courses return ko "instantaneous repositioning" treat karte hain aur drop kar dete hain (183). Hamesha apna convention clearly batao — grader dekhna chahta hai tumne kaunsa assume kiya.
Exercise 3.3 (L3) — C-LOOK
Same queue/head ke liye C-LOOK (up first) wrap count karke compute karo. C-SCAN(a) se compare karo.
Recall Solution 3.3
C-LOOK last up-request (183) par rukta hai aur lowest request (14) par jump karta hai, 0 par nahi. Up: , jump , phir upar: .
- Last tak upar: .
- Jump back: .
- Resume up: .
C-SCAN(a) se compare karo: C-LOOK bachata hai kyunki empty stretches (top) aur (bottom) se bachta hai. Exactly . ✔
Level 4 — Synthesis
Exercise 4.1 (L4) — Rank them all
Queue 98, 183, 37, 122, 14, 124, 65, 67, head 53, up-first, range 0–199 ke liye FCFS / SCAN / LOOK / C-SCAN(with wrap) / C-LOOK(with wrap) ke totals list karo aur least se most head movement tak rank karo.
Recall Solution 4.1
Parent note aur Exercises 3.2–3.3 se:
- FCFS
- SCAN
- LOOK
- C-SCAN (wrap)
- C-LOOK (wrap)
Ranking (least → most travel): Yeh order kyun sense karta hai: elevators (LOOK/SCAN) FCFS ko zig-zag khatam karke beat karte hain. Elevators mein, "no boundary trip" (LOOK) "boundary trip" (SCAN) ko beat karta hai, aur circular versions wrap cost add karte hain. FCFS sabse worst hai kyunki yeh geometry ko completely ignore karta hai.
Ranking ka visual summary:

Exercise 4.2 (L4) — Build a worst case for FCFS
Exactly 4 requests ki ek request queue design karo (head 100 par, range 0–199) jo FCFS ka total head movement jitna ho sake utna bada banaye. Wo maximum kitna hai, aur kaun sa ordering usse achieve karta hai?
Recall Solution 4.2
KYA exploit karein: FCFS har consecutive pair ke liye pay karta hai, to hum chahte hain har consecutive pair full disk span kare, extremes alternate karte hue. Queue: (head 100 se start karta hai). Yeh (near) maximal kyun hai: pehla move ek extreme par land karne ke baad, baad ki har move full-width swing hai. Sirf "waste-limited" term pehla hai (, kyunki head beech mein start kiya). Agar head extreme par start karta (say 0) to milta, jo 4 full-swing requests ke liye true maximum hai. Lesson: FCFS ka worst case sirf iss baat se bounded hai ki arrival order kitna adversarial hai — exactly isliye smarter scheduling exist karta hai.
Level 5 — Mastery
Exercise 5.1 (L5) — Prove the SCAN vs LOOK gap
Head par start karta hai, upar jaata hai pehle. largest requested cylinder hai () aur smallest requested cylinder hai (), disk range ke saath. Prove karo ki (Assume karo ki se neeche kam se kam ek request hai, to dono algorithms reverse karte hain aur tak neeche sweep karte hain.)
Recall Solution 5.1
LOOK (up first): last request tak upar jao, phir smallest tak neeche. SCAN (up first): poore tak upar jao, phir tak neeche. Subtract karo: Exactly yahi kyun aur kuch nahi: dono trips ka down-portion same par khatam hota hai; sirf yeh farq hai ki reverse karne se pehle head kitna upar gaya — vs — aur wo overshoot do baar pay hota hai (ek baar upar jaate hue, ek baar neeche wapas aate hue). Start cancel ho jaata hai kyunki dono algorithms same jagah se shuru karte hain. Yeh parent note ke rule ka algebra hai: "difference ."
Exercise 5.2 (L5) — Latency-aware decision
Ek disk range 0–199 mein yeh pending queue hai (head 100 par): 101, 102, 103, 0, 199. Rotational latency negligible hai; seek dominate karta hai. Cylinder 199 par ek real-time request ko 120 cylinders ke movement budget mein serve karna zaroori hai warna deadline miss ho jaati hai. SCAN up-first ke under, cylinder 199 apni deadline meet karta hai? FCFS (arrival order as listed) ke under? Is deadline ke liye OS ko kaunsi policy choose karni chahiye, aur total travel mein uski cost kya hai?
Recall Solution 5.2
SCAN up-first: (phir down ). 199 reach karne tak movement: cylinders ✔ — deadline met. Total SCAN travel: up , down → .
FCFS (order 101, 102, 103, 0, 199): head visit karta hai . 199 reach karne tak movement = saare prior legs plus last ka sum: (0 tak neeche detour 199 se pehle budget blow kar deta hai.) Total FCFS travel yahan .
Decision: SCAN (up-first) choose karo. Yeh 199 deadline meet karta hai (99 ≤ 120) aur total travel kam hai (298 < 305). Yahan elevator dono axes par jeetta hai — lekin general point (dekho I/O Subsystem and Device Drivers) yeh hai ki real schedulers deadlines weigh karte hain, sirf raw sum nahi.
Recall One-line self-test recap
LOOK ≤ SCAN by 2×(end−last) ::: 5.1 mein prove kiya FCFS kabhi reorder nahi karta ::: chahe sorting help kare (2.1 trap) C-SCAN fairness ke liye wrap jump pay karta hai ::: 382 wrap ke saath vs 183 bina wrap (3.2) Direction SCAN ka total bahut change kar sakta hai ::: 331 up-first vs 236 down-first (3.1) "Best" ke liye metric chahiye ::: total travel vs fairness vs deadline (4.1 trap, 5.2)
Connections
- 4.2.38 Disk scheduling — FCFS, SCAN, C-SCAN, LOOK (Hinglish)
- Seek time vs Rotational latency
- Hard Disk Drive structure (cylinders, tracks, sectors)
- Process Scheduling — FCFS, SJF, Round Robin
- Starvation and Fairness in OS
- SSTF (Shortest Seek Time First)
- I/O Subsystem and Device Drivers