Process states (new, ready, running, waiting, terminated) in Operating Systems - Time & Space Complexity
We want to understand how the time spent by a process changes as it moves through different states in an operating system.
How does the number of steps or transitions grow as the process runs?
Analyze the time complexity of the following process state transitions.
// Pseudocode for process state transitions
state = "new"
while state != "terminated":
if state == "new":
state = "ready"
else if state == "ready":
state = "running"
else if state == "running":
if needs_io:
state = "waiting"
else:
state = "terminated"
else if state == "waiting":
state = "ready"
// repeat until terminated
This code models how a process moves through states until it finishes.
Look for loops or repeated steps in the process state changes.
- Primary operation: The loop that changes the process state repeatedly.
- How many times: Depends on how many times the process needs CPU and I/O before termination.
The number of state transitions grows with how many CPU bursts and I/O waits the process has.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 (few I/O) | About 20 state changes |
| 100 (moderate I/O) | About 200 state changes |
| 1000 (many I/O) | About 2000 state changes |
Pattern observation: The total steps increase roughly in direct proportion to the number of CPU and I/O cycles.
Time Complexity: O(n)
This means the total number of state transitions grows linearly with the number of CPU and I/O cycles the process performs.
[X] Wrong: "The process state changes happen instantly and do not add up."
[OK] Correct: Each state change takes time and the total time depends on how many times the process switches states before finishing.
Understanding how process states change and how that affects execution time helps you explain how operating systems manage tasks efficiently.
"What if the process never needs I/O and runs straight to termination? How would the time complexity change?"