FCFS disk scheduling in Operating Systems - Time & Space Complexity
We want to understand how the time to complete disk requests grows as more requests come in when using FCFS disk scheduling.
Specifically, how does the number of disk movements increase with the number of requests?
Analyze the time complexity of the following FCFS disk scheduling code snippet.
int total_movement = 0;
int current_position = start_position;
for (int i = 0; i < n; i++) {
total_movement += abs(requests[i] - current_position);
current_position = requests[i];
}
return total_movement;
This code calculates the total head movement by servicing disk requests in the order they arrive.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through each disk request once.
- How many times: Exactly once per request, so n times.
As the number of requests increases, the total operations grow directly with the number of requests.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 operations |
| 100 | 100 operations |
| 1000 | 1000 operations |
Pattern observation: The work grows in a straight line with the number of requests.
Time Complexity: O(n)
This means the time to process all requests grows directly in proportion to how many requests there are.
[X] Wrong: "The time depends on how far the disk head moves, so it could be more than linear."
[OK] Correct: While the total movement distance varies, the number of steps in the code is always one per request, so time complexity is based on request count, not distance.
Understanding how FCFS disk scheduling scales helps you explain simple scheduling algorithms clearly and shows you can analyze how work grows with input size.
"What if we changed FCFS to a scheduling algorithm that sorts requests before processing? How would the time complexity change?"
Practice
Solution
Step 1: Understand the abbreviation FCFS
FCFS is a common term in scheduling that means requests are handled in the order they arrive.Step 2: Match the full form
First-Come, First-Served matches the concept of serving requests in arrival order.Final Answer:
First-Come, First-Served -> Option BQuick Check:
FCFS = First-Come, First-Served [OK]
- Confusing FCFS with other scheduling algorithms
- Thinking FCFS means fastest service
- Mixing up the abbreviation letters
Solution
Step 1: Recall FCFS scheduling principle
FCFS processes disk requests in the exact order they arrive without reordering.Step 2: Compare options with FCFS behavior
Only Processes requests in the order they arrive matches this behavior exactly.Final Answer:
Processes requests in the order they arrive -> Option AQuick Check:
FCFS = order of arrival [OK]
- Choosing shortest seek time instead of arrival order
- Confusing with priority scheduling
- Assuming outermost track first
[55, 58, 60, 70, 18] and the disk head starting at track 50, what is the total head movement using FCFS scheduling?Solution
Step 1: Calculate head movements in FCFS order
Start at 50, move to 55 (5), then 58 (3), then 60 (2), then 70 (10), then 18 (52). Total = 5+3+2+10+52 = 72.Step 2: Verify calculation carefully
Recalculate: 5 + 3 + 2 + 10 + 52 = 72 confirmed.Final Answer:
72 -> Option AQuick Check:
Sum of movements = 72 [OK]
- Adding distances incorrectly
- Mixing request order
- Forgetting to include last move
Solution
Step 1: Check the request order in calculation
The requests are [50, 40, 55], so after 50, the head should move to 40, then 55.Step 2: Verify the distances in correct order
Calculate: |45-50|=5, |50-40|=10, |40-55|=15; total = 5+10+15=30, not 25.Final Answer:
The order of requests is incorrect in calculation -> Option DQuick Check:
Correct order matters for total movement [OK]
- Mixing request order
- Ignoring absolute distance
- Miscounting starting position
[120, 10, 50, 90]. Using FCFS scheduling, what is the total head movement? How does this compare to SSTF (Shortest Seek Time First) scheduling for the same requests?Solution
Step 1: Calculate FCFS total head movement
100->120 (20), 120->10 (110), 10->50 (40), 50->90 (40). Total = 20+110+40+40 = 210.Step 2: Calculate SSTF total head movement
From 100 closest is 90 (10)->90; closest 120 (30)->120; closest 50 (70)->50; then 10 (40). Total = 10+30+70+40 = 150.Step 3: Compare
SSTF (150) reduces movement compared to FCFS (210).Final Answer:
FCFS: 210, SSTF: 150; SSTF reduces movement -> Option CQuick Check:
SSTF reduces head movement compared to FCFS [OK]
- Mixing request order in FCFS
- Misordering SSTF requests
- Ignoring large jumps in FCFS
Ready to prove it?
Pass the test and this pattern moves unknown
