I am checking simple order of complexity problems and I found this one:
int example(int max) {
int i = 0;
double x = 0.0;
while ( i <= max ) {
x = doStuff(x , i); //doStuff is O(i)
i = i + 10 ;
}
}
We know that doStuff(int x, int i)
is of O(i)
, and that the order of example should be based on max
.
Now, i have seen and understood cases of loops running in O(i)
,O(log i)
, etc...but how would I get the order of the while loop (and thus the order of example
) when the index being checked and also passed to the function does grow in sums different than other usual i++
or 2*i
?