Hypothetically, lets say we have these two methods:
void example(int p){
p += 10;
p = exampleTwo(p);
}
int exampleTwo(int p){
int pp = 0;
for(int i = 0; i < p; i++){
pp++;
}
return pp;
}
The method exampleTwo has a linear runtime. Its run time is O(n).
So, what is the big O notation of the method example, taking into account that it calls exampleTwo?
I would imagine it is also O(n), but I do not know for sure.
For subroutines, you should multiply the order by the order of the number of the number of times it is called. For example, if a function is called O(n) times, and runs in O(log n) time, the total order is O(n log n).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With