SSTF (Shortest Seek Time First) in Operating Systems - Time & Space Complexity
Analyzing time complexity helps us understand how the SSTF disk scheduling algorithm performs as the number of disk requests grows.
We want to know how the time to select the next request changes when there are more requests waiting.
Analyze the time complexity of the following SSTF selection process.
function selectNextRequest(currentPosition, requests) {
let shortestDistance = Infinity;
let nextRequest = null;
for (let i = 0; i < requests.length; i++) {
let distance = Math.abs(requests[i] - currentPosition);
if (distance < shortestDistance) {
shortestDistance = distance;
nextRequest = requests[i];
}
}
return nextRequest;
}
This code finds the disk request closest to the current head position by checking all pending requests.
Look for repeated actions that take time.
- Primary operation: Loop through all disk requests to find the closest one.
- How many times: Once per selection, looping over all requests (n times).
As the number of requests increases, the time to find the closest request grows proportionally.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 checks |
| 100 | About 100 checks |
| 1000 | About 1000 checks |
Pattern observation: The number of operations grows directly with the number of requests.
Time Complexity: O(n)
This means the time to pick the next request grows linearly as more requests are waiting.
[X] Wrong: "SSTF instantly finds the closest request regardless of how many requests there are."
[OK] Correct: SSTF must check each request to find the closest one, so more requests mean more work.
Understanding how SSTF scales helps you explain disk scheduling choices clearly and shows you can analyze algorithm efficiency in real systems.
"What if the requests were kept sorted by position? How would that affect the time complexity of finding the next request?"
Practice
Solution
Step 1: Understand SSTF purpose
SSTF aims to reduce the seek time by choosing the disk request nearest to the current head position.Step 2: Compare options with SSTF behavior
Only the request closest to the current head position matches this behavior; others describe different algorithms.Final Answer:
The request closest to the current head position -> Option AQuick Check:
SSTF = closest request [OK]
- Confusing SSTF with FCFS (First Come First Serve)
- Thinking SSTF picks requests in arrival order
- Assuming SSTF picks the farthest request
Solution
Step 1: Review SSTF definition
SSTF selects the disk request closest to the current head position to minimize seek time.Step 2: Match options with SSTF behavior
The option "It selects the request closest to the current head position." correctly describes SSTF. Other options describe different algorithms like FCFS or SCAN.Final Answer:
It selects the request closest to the current head position. -> Option CQuick Check:
SSTF = closest request selection [OK]
- Mixing SSTF with FCFS or SCAN algorithms
- Assuming SSTF picks requests by waiting time
- Confusing direction-based scheduling with SSTF
Solution
Step 1: Calculate distances from head position 50
Distances: 45 (5), 70 (20), 10 (40), 55 (5)Step 2: Identify closest request
Requests at 45 and 55 are both 5 units away. SSTF can pick either, but usually picks the first closest found, here 45.Final Answer:
45 -> Option AQuick Check:
Closest request = 45 [OK]
- Choosing the farthest request by mistake
- Ignoring equal distances and picking wrong one
- Confusing SSTF with FCFS order
Solution
Step 1: Calculate distances from head position 30
Distances: 35 (5), 25 (5), 40 (10), 20 (10)Step 2: Identify correct SSTF choice
Closest requests are 35 and 25 (5 units away). Choosing 40 (10 units) is incorrect.Final Answer:
They chose the farthest request instead of the closest. -> Option BQuick Check:
SSTF picks closest, not farthest [OK]
- Picking requests based on arrival time
- Ignoring actual distances from head
- Confusing SSTF with other algorithms
Solution
Step 1: Start at head position 100 and find closest request
Distances: 120(20), 89(11), 130(30), 80(20), 110(10). Closest is 110 (10 units).Step 2: Move head to 110 and repeat
Remaining: 120(10), 89(21), 130(20), 80(30). Closest is 120 (10).Step 3: Move head to 120 and repeat
Remaining: 89(31), 130(10), 80(40). Closest is 130 (10).Step 4: Move head to 130 and repeat
Remaining: 89(41), 80(50). Closest is 89 (41).Step 5: Move head to 89 and last request is 80 (9 away)
Order: 110, 120, 130, 89, 80.Final Answer:
[110, 120, 130, 89, 80] -> Option DQuick Check:
SSTF services closest request each step [OK]
- Not updating head position after each request
- Choosing requests by arrival order
- Ignoring equal distances and picking wrong request
Ready to prove it?
Pass the test and this pattern moves unknown
