int foo(int n)
{
int sum = 0;
for(int k=1; k <= n; k = k * 2)
{
sum += k;
}
return sum;
}
I have the following function. Now, according to me the runtime complexity of foo(n) should be big-o(logn). Now, I am asked to find out the run time complexity of foo(n*n*n*n). What should it be? According to me, it should be, big-o(logn) only. Am I right in saying this?
It is O(log n4) → O(4 log n) → O(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