0
0
ARM Architectureknowledge~5 mins

Why branching controls program execution in ARM Architecture - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why branching controls program execution
O(1)
Understanding Time Complexity

Branching changes which instructions run next in a program. Understanding its time cost helps us see how programs behave as they make decisions.

We ask: How does branching affect the number of steps a program takes?

Scenario Under Consideration

Analyze the time complexity of the following code snippet.

    
    CMP R0, #0        
    BEQ label_zero   
    ADD R1, R1, #1  
    B end            
label_zero:         
    SUB R1, R1, #1  
end:                
    MOV R2, R1      
    

This code compares a value and branches to different instructions based on the result, controlling which operations run.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Single conditional branch deciding which instruction to run next.
  • How many times: This snippet runs once per execution; no loops or repeated branches here.
How Execution Grows With Input

Explain the growth pattern intuitively.

Input Size (n)Approx. Operations
1About 5 instructions
10About 50 instructions if repeated 10 times
100About 500 instructions if repeated 100 times

Pattern observation: Each run executes a fixed number of steps; branching only changes which steps run, not how many.

Final Time Complexity

Time Complexity: O(1)

This means the number of steps stays the same no matter the input; branching just picks the path.

Common Mistake

[X] Wrong: "Branching always makes the program slower because it adds extra steps."

[OK] Correct: Branching only chooses which instructions run; it does not add extra repeated work by itself.

Interview Connect

Understanding how branching affects program steps helps you explain decision-making in code clearly and confidently.

Self-Check

"What if the branch was inside a loop running n times? How would the time complexity change?"