Square Root Time Complexity

340 Views Asked by At

I'm deeply sorry for this, I don't know if it's the appropriate place to post this but I just can't figure out what's the time complexity of this algorithm:

int fun(int n)
{
    int j = 10;
    while( j < n)
        j+= sqrt(j);
    return j;
}

I know that at the $k^{th}$ iteration we have $f(k)=f(k-1)+\sqrt{f(k-1)}$, with $f(0)=10$, I tried solving this function, but I couldn't find any way to do so.

2

There are 2 best solutions below

11
On

You can see that the second derivative of the function is a constant value, so you can approximate it with a quadratic function.

The values for $a$ and $b$ in the quadratic function take on values of around $0.00001$, so $$f(n) \approx 0.00001n^2+0.00001n+10$$

1
On

Are you looking for the time complexity or the value of the function? You add at least $3$ every cycle. The number of loops is then less than or equal to $\frac 13(n-10)+1$ so the time complexity is $O(n)$