LOOK and C-LOOK variants in Operating Systems - Time & Space Complexity
We want to understand how the time to schedule disk requests grows as the number of requests increases in LOOK and C-LOOK algorithms.
How does the number of disk requests affect the total operations needed to service them?
Analyze the time complexity of the LOOK disk scheduling algorithm variant.
function LOOK(requests, head) {
sort requests by track number
direction = choose initial direction
while requests remain {
move head in direction servicing requests until no more in that direction
reverse direction
}
}
This code moves the disk head back and forth, servicing requests in order along the track numbers.
We look for repeated actions that affect time.
- Primary operation: Scanning and servicing requests in sorted order along the disk tracks.
- How many times: Each request is visited once during the head movement in one direction.
As the number of requests grows, the head must move to each request once, scanning through them in order.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 moves to service all requests |
| 100 | About 100 moves, scanning through requests |
| 1000 | About 1000 moves, one per request |
Pattern observation: The operations grow roughly in direct proportion to the number of requests.
Time Complexity: O(n log n)
This means the time to service all requests grows linearly with the number of requests after sorting.
[X] Wrong: "LOOK and C-LOOK algorithms take longer than scanning all requests because they move the head back and forth multiple times."
[OK] Correct: Each request is serviced once in order, so the total work grows linearly after sorting. The back-and-forth movement is efficient and does not multiply the work.
Understanding how disk scheduling algorithms scale helps you explain system efficiency clearly and confidently in interviews.
What if the requests were not sorted first? How would that affect the time complexity?
Practice
Solution
Step 1: Understand LOOK algorithm movement
LOOK moves the disk head back and forth servicing requests only as far as needed in each direction.Step 2: Understand C-LOOK algorithm movement
C-LOOK moves the disk head in one direction only and jumps back to the start without servicing requests on the return.Final Answer:
LOOK moves the disk head back and forth, while C-LOOK moves in one direction and jumps back. -> Option DQuick Check:
LOOK vs C-LOOK movement = back/forth vs one-way jump [OK]
- Confusing direction of head movement
- Thinking C-LOOK moves back and forth
- Mixing up scheduling order
Solution
Step 1: Identify C-LOOK movement pattern
C-LOOK moves the disk head in one direction only, servicing requests along the way.Step 2: Understand jump back behavior
After reaching the last request in that direction, the head jumps back to the first request without servicing on the return.Final Answer:
The head moves in one direction and then jumps back to the first request. -> Option BQuick Check:
C-LOOK = one-way move + jump back [OK]
- Assuming head moves back and forth
- Confusing C-LOOK with LOOK
- Thinking head services requests on return jump
Solution
Step 1: Move head towards higher requests
Starting at 15, LOOK moves up servicing 20, 22, and 40.Step 2: Reverse direction and service lower requests
After 40, head moves back down servicing 10, 6, and 2. But LOOK only goes as far as the last request in each direction. Since 10 is before 15, it will be serviced on the return.Step 3: Verify options
[20, 22, 40, 6, 2] lists only requests serviced in one direction (20, 22, 40) without the return. LOOK services both directions, so [20, 22, 40, 6, 2] is incomplete. [20, 22, 40, 10, 6, 2] includes 10, 6, 2 after 40, which matches LOOK behavior.Final Answer:
[20, 22, 40, 10, 6, 2] -> Option AQuick Check:
LOOK = up then down servicing all requests [OK]
- Ignoring requests on return path
- Assuming C-LOOK behavior
- Ordering requests incorrectly
Solution
Step 1: Understand C-LOOK movement
C-LOOK moves the head in one direction servicing requests from lowest to highest.Step 2: Check return path behavior
Unlike LOOK, C-LOOK does not service requests on the return jump; it jumps back to the start without servicing.Final Answer:
C-LOOK does not move back to service requests; it jumps back without servicing. -> Option AQuick Check:
C-LOOK jump back skips servicing requests [OK]
- Assuming servicing on return jump
- Confusing C-LOOK with LOOK
- Misunderstanding head movement direction
Solution
Step 1: Service requests moving up from 20
The head moves from 20 to 25, then 35, then 45. Distance = 45 - 20 = 25.Step 2: Jump back to lowest request and service upwards
After 45, the head jumps back to 5 (distance = 45 - 5 = 40, but jump is not counted as movement in C-LOOK). Then it services 5 and 15 moving up. Distance from 5 to 15 = 10.Step 3: Calculate total movement
Total movement = 25 (upwards) + 10 (from 5 to 15) = 35. But jump back is considered instantaneous (no movement counted). So total movement is 25 + 10 = 35.Step 4: Re-examine options
Total movement of 35 matches 35.Final Answer:
35 -> Option CQuick Check:
C-LOOK counts only servicing moves, jump back ignored [OK]
- Counting jump back as movement
- Ignoring requests before head position
- Adding distances incorrectly
Ready to prove it?
Pass the test and this pattern moves unknown
