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];
}
Statement | Times Executed | Steps per Execution | Total Steps |
---|---|---|---|
int i = 0; | 1 | 1 | 1 |
i < n (comparison) | n + 1 | 1 | n + 1 |
sum += list[i]; | n | 1 | n |
i++ (increment) | n | 1 | n |
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 .