Scheduling criteria (turnaround time, waiting time, throughput) in Operating Systems - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When we analyze scheduling criteria like turnaround time, waiting time, and throughput, we want to understand how the time taken by the system changes as the number of processes grows.
We ask: How does the system's work increase when more tasks need scheduling?
Analyze the time complexity of calculating scheduling criteria for a list of processes.
for each process in process_list:
calculate turnaround_time = completion_time - arrival_time
calculate waiting_time = turnaround_time - burst_time
calculate throughput = total_processes / total_time
This code calculates turnaround time and waiting time for each process, then computes throughput for all processes.
Look for repeated steps that take most time.
- Primary operation: Looping through each process to calculate turnaround and waiting times.
- How many times: Once for every process in the list.
As the number of processes increases, the calculations grow in a simple way.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 calculations for turnaround and waiting times |
| 100 | About 100 calculations |
| 1000 | About 1000 calculations |
Pattern observation: The work grows directly with the number of processes, doubling the processes doubles the work.
Time Complexity: O(n)
This means the time to calculate scheduling criteria grows in a straight line with the number of processes.
[X] Wrong: "Calculating turnaround and waiting times takes the same time no matter how many processes there are."
[OK] Correct: Each process needs its own calculation, so more processes mean more work and more time.
Understanding how scheduling calculations scale helps you explain system performance clearly and shows you grasp how operating systems handle many tasks efficiently.
"What if we had to recalculate waiting times every time a new process arrives? How would that affect the time complexity?"
Practice
Solution
Step 1: Understand the definition of turnaround time
Turnaround time is the total time from when a process arrives until it finishes execution.Step 2: Compare with other criteria
Waiting time is only the time a process waits before starting, throughput is number of processes completed per time, and response time is time until first response.Final Answer:
Turnaround time -> Option AQuick Check:
Turnaround time = total process duration [OK]
- Confusing waiting time with turnaround time
- Mixing throughput with time durations
- Thinking response time equals turnaround time
Solution
Step 1: Define waiting time
Waiting time is the time a process spends waiting in the ready queue before it starts running on the CPU.Step 2: Eliminate other options
Time from process arrival to completion describes turnaround time, C describes throughput, and D is CPU burst time, not waiting time.Final Answer:
Time a process spends in the ready queue before execution -> Option CQuick Check:
Waiting time = time before execution [OK]
- Confusing waiting time with turnaround time
- Thinking waiting time includes execution time
- Mixing throughput with waiting time
Solution
Step 1: Calculate total processes completed
All three processes (P1, P2, P3) completed within 20 seconds, so total completed = 3.Step 2: Calculate throughput
Throughput = number of processes completed / total time = 3 / 20 = 0.15 processes per second.Final Answer:
0.15 processes per second -> Option BQuick Check:
Throughput = 3/20 = 0.15 [OK]
- Dividing total time by number of processes instead of reverse
- Counting incomplete processes
- Using average completion time instead of total time
Solution
Step 1: Understand waiting time formula
Waiting time = Start time - Arrival time = 5 - 0 = 5 seconds.Step 2: Identify error in reported waiting time
The reported waiting time of 7 seconds is incorrect because it does not match the formula.Final Answer:
5 seconds -> Option AQuick Check:
Waiting time = start - arrival = 5 [OK]
- Using completion time instead of start time
- Adding instead of subtracting times
- Confusing waiting time with turnaround time
P1: arrival=0, burst=4P2: arrival=1, burst=3P3: arrival=2, burst=1P4: arrival=3, burst=3If the scheduler uses First-Come-First-Serve (FCFS), what is the average turnaround time?
Solution
Step 1: Calculate completion times using FCFS
Process order by arrival: P1(0), P2(1), P3(2), P4(3).
P1 completes at 0+4=4,
P2 starts at 4, completes at 4+3=7,
P3 starts at 7, completes at 7+1=8,
P4 starts at 8, completes at 8+3=11.Step 2: Calculate turnaround times
Turnaround = completion - arrival:
P1: 4-0=4,
P2: 7-1=6,
P3: 8-2=6,
P4: 11-3=8.
Average turnaround = (4+6+6+8)/4 = 24/4 = 6.0 seconds.Final Answer:
6.0 seconds -> Option DQuick Check:
Average turnaround = 24/4 = 6.0 [OK]
- Calculating turnaround as burst time only
- Ignoring arrival times in scheduling order
- Mixing waiting time with turnaround time
