0
0
Operating Systemsknowledge~5 mins

Process states (new, ready, running, waiting, terminated) in Operating Systems - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Process states (new, ready, running, waiting, terminated)
O(n)
Understanding Time 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?

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

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.

Final Time Complexity

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.

Common Mistake

[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.

Interview Connect

Understanding how process states change and how that affects execution time helps you explain how operating systems manage tasks efficiently.

Self-Check

"What if the process never needs I/O and runs straight to termination? How would the time complexity change?"