0
0
Software Engineeringknowledge~5 mins

White-box testing techniques in Software Engineering - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: White-box testing techniques
O(n)
Understanding Time Complexity

When we analyze white-box testing techniques, we want to understand how the time needed to test code grows as the code size or complexity increases.

We ask: How does the effort to run these tests change when the program gets bigger?

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


for (int i = 0; i < n; i++) {
    if (condition(i)) {
        executeBranchA();
    } else {
        executeBranchB();
    }
}

This code represents a simple white-box test that checks each part of the code by running through all possible branches once.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: The for-loop runs through each element from 0 to n-1.
  • How many times: Exactly n times, once per element.
How Execution Grows With Input

As the input size n grows, the number of operations grows in a straight line.

Input Size (n)Approx. Operations
10About 10 checks and branch executions
100About 100 checks and branch executions
1000About 1000 checks and branch executions

Pattern observation: The work grows evenly as the input grows; doubling input doubles work.

Final Time Complexity

Time Complexity: O(n)

This means the testing effort grows directly in proportion to the size of the code or input being tested.

Common Mistake

[X] Wrong: "Testing all branches means the time grows much faster than the code size."

[OK] Correct: Each branch is checked once per input, so time grows linearly, not exponentially.

Interview Connect

Understanding how testing time grows helps you plan and explain your testing approach clearly in real projects and interviews.

Self-Check

"What if the code had nested loops inside the branches? How would the time complexity change?"