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?