example()
has no loop, it does nothing extra to exampleTwo()
so it has the same order of complexity, i.e. O(n)
, as exampleTwo()
.
If example()
is changed to this:
int example(int p){
int sum = 0;
for(int i=0; i<p; ++i){
sum += exampleTwo(p);
}
return sum;
}
then the complexity is now O(n²)
: as p
gets bigger the amount of work to do increases by the square of p
.