FCFS (First Come First Served) in Operating Systems - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
Analyzing time complexity helps us understand how the FCFS scheduling algorithm performs as the number of processes increases.
We want to know how the work done grows when more processes arrive.
Analyze the time complexity of the following FCFS scheduling code snippet.
for each process in process_list:
wait_time = sum of burst times of all previous processes
turnaround_time = wait_time + current process burst time
record wait_time and turnaround_time
This code calculates waiting and turnaround times for each process in the order they arrive.
Look at what repeats as the input grows.
- Primary operation: For each process, summing burst times of all previous processes.
- How many times: For each of the n processes, it sums up to n-1 previous burst times.
As the number of processes increases, the total work grows faster because each process sums more burst times.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 55 sums (1+2+...+9) |
| 100 | About 4,950 sums |
| 1000 | About 499,500 sums |
Pattern observation: The total operations grow roughly like the square of the number of processes.
Time Complexity: O(n2)
This means the work needed grows quickly as more processes are added, because each process waits for all before it.
[X] Wrong: "Calculating waiting times in FCFS is always fast and simple, so it must be O(n)."
[OK] Correct: Because each process's wait time depends on all previous processes, the total work adds up more than just once per process.
Understanding how FCFS scales helps you explain scheduling choices clearly and shows you can think about how algorithms behave as systems grow.
"What if we stored cumulative burst times as we go instead of summing each time? How would the time complexity change?"
Practice
Solution
Step 1: Understand FCFS concept
FCFS means tasks are processed in the order they come, like a queue.Step 2: Compare options
Only Processes are handled in the order they arrive. describes this order-based processing correctly.Final Answer:
Processes are handled in the order they arrive. -> Option BQuick Check:
FCFS = Order of arrival [OK]
- Confusing FCFS with priority scheduling
- Thinking shortest tasks go first
- Assuming random order
Solution
Step 1: Identify FCFS scheduling traits
FCFS schedules tasks in arrival order and does not interrupt running tasks.Step 2: Match options to traits
Processes are scheduled in the order they arrive without preemption. correctly states no preemption and order of arrival.Final Answer:
Processes are scheduled in the order they arrive without preemption. -> Option AQuick Check:
FCFS = Arrival order + no preemption [OK]
- Mixing FCFS with priority or shortest job scheduling
- Assuming tasks can be interrupted
- Thinking scheduling is random
Solution
Step 1: Calculate completion of first process
Process 1 arrives at 0 and runs for 5 units, finishing at time 5.Step 2: Calculate completion of second process
Process 2 arrives at 2 but waits until process 1 finishes at 5, then runs for 3 units, finishing at 8.Final Answer:
8 -> Option CQuick Check:
Process 2 finishes at 5+3=8 [OK]
- Starting second process at its arrival time instead of after first finishes
- Adding arrival times incorrectly
- Ignoring waiting time
processes = [(0, 4), (1, 3), (2, 1)] # (arrival, burst)
completion = []
current_time = 0
for arrival, burst in processes:
if arrival > current_time:
current_time = arrival
completion.append(current_time)
current_time += burst
print(completion)Solution
Step 1: Analyze code logic
Completion time is appended before current_time is updated with burst time, causing wrong values.Step 2: Identify correct order
We must update current_time by adding burst before appending completion time to reflect actual finish time.Final Answer:
Appending completion time before updating current_time. -> Option DQuick Check:
Update time before recording completion [OK]
- Appending completion time too early
- Ignoring arrival time adjustments
- Confusing process order
Solution
Step 1: Understand FCFS impact of longer burst
FCFS runs processes fully in arrival order, so a longer first process delays all others.Step 2: Analyze waiting time effect on third process
The third process must wait until the first and second finish, so longer first process increases its waiting time.Final Answer:
The third process waits longer because the first process delays the queue. -> Option AQuick Check:
Longer first task = longer wait for later tasks [OK]
- Assuming later tasks start earlier
- Ignoring impact of burst time changes
- Thinking FCFS skips tasks
