Performance Analysis

  • space complexity
  • time complexity

Space Complexity

  • : fixed space requirements
  • : usage depends on input

Time Complexity increase for each recursive.

Time Complexity

  • : fixed space requirements.
  • : depends on the input.

Program step

Counting method

Introduce variable count into programs e.g.

float sum (float list[], int n) {
    float tempsum = 0;
    count++; // Assignment operation
    for (int i = 0; i < n; i++) {
        count++; // For loop increment
        tempsum += list[i];
        count++; // Assignment operation
    }
    count++; // For loop final check
    return tempsum;
    count++; // Return statement
}

Tabular Method

For each statement, calculate how many times it is executed and multiply this by the number of steps per execution. Then, sum the contributions from all statements.

e.g.

for (int i = 0; i < n; i++) {
    sum += list[i];
}
StatementTimes ExecutedSteps per ExecutionTotal Steps
int i = 0;111
i < n (comparison)n + 11n + 1
sum += list[i];n1n
i++ (increment)n1n
Total Steps= 1 + (n + 1) + n + n = 3n + 2

Asymptotic notation

Big-O ()

the upper bound of function, for all

Omega

the lower bound of function, for all

Theta

the exact bound of function, for all

e.g.

  • For :
    • because for all .
    • because for all .
    • because for all .
  • For :
    • because for all .
    • because for all .
    • because for all .