0
0
Compiler Designknowledge~5 mins

Target machine model in Compiler Design - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Target machine model
O(n)
Understanding Time Complexity

When we study the target machine model, we want to understand how the cost of running compiled code grows as the input size grows.

We ask: how does the machine's design affect the time it takes to execute instructions as programs get bigger?

Scenario Under Consideration

Analyze the time complexity of the following simplified instruction execution model.


for each instruction in program:
    decode instruction
    execute instruction
    if instruction is jump:
        update program counter
    

This snippet models how a target machine processes each instruction in a program sequentially, with special handling for jump instructions.

Identify Repeating Operations

Look at what repeats as the program runs.

  • Primary operation: Executing each instruction one by one.
  • How many times: Once for every instruction in the program.
How Execution Grows With Input

As the number of instructions increases, the total execution steps increase roughly the same amount.

Input Size (n)Approx. Operations
10About 10 instruction executions
100About 100 instruction executions
1000About 1000 instruction executions

Pattern observation: The work grows directly with the number of instructions.

Final Time Complexity

Time Complexity: O(n)

This means the time to run the program grows in a straight line as the program gets longer.

Common Mistake

[X] Wrong: "Jump instructions make the execution time much faster or slower in a way that changes overall growth."

[OK] Correct: While jumps change the order of execution, each instruction still runs once in sequence, so total time grows linearly with program size.

Interview Connect

Understanding how a target machine executes instructions helps you explain how programs run and how compilers translate code efficiently.

Self-Check

"What if the target machine could execute multiple instructions at the same time? How would the time complexity change?"