0
0
Embedded Cprogramming~5 mins

Wake-up sources configuration in Embedded C - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Wake-up sources configuration
O(n)
Understanding Time Complexity

When configuring wake-up sources in embedded systems, it's important to know how the time to set them up changes as the number of sources grows.

We want to understand how the setup time scales when more wake-up sources are added.

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


void configureWakeupSources(int *sources, int count) {
    for (int i = 0; i < count; i++) {
        enableWakeupSource(sources[i]);
    }
}

// Enables a single wake-up source
void enableWakeupSource(int source) {
    // Hardware register setup here
}
    

This code sets up each wake-up source one by one by calling a function for each source.

Identify Repeating Operations
  • Primary operation: Loop over the array of wake-up sources.
  • How many times: Exactly once for each source, so count times.
How Execution Grows With Input

As the number of wake-up sources increases, the time to configure them grows in a straight line.

Input Size (count)Approx. Operations
1010 calls to enableWakeupSource
100100 calls to enableWakeupSource
10001000 calls to enableWakeupSource

Pattern observation: The setup time grows directly with the number of sources; doubling sources doubles the work.

Final Time Complexity

Time Complexity: O(n)

This means the time to configure wake-up sources grows linearly with how many sources you have.

Common Mistake

[X] Wrong: "Configuring multiple wake-up sources takes the same time no matter how many there are."

[OK] Correct: Each source requires a separate setup step, so more sources mean more work and more time.

Interview Connect

Understanding how setup time grows with input size helps you explain system behavior clearly and shows you can think about efficiency in embedded programming.

Self-Check

"What if we batch configure all wake-up sources in one hardware call instead of individually? How would the time complexity change?"