I needed a square root approximation in C so I looked up this post and got this following implementation:
float squareroot(float n)
{
float x = n;
float y = 1;
float e = 0.001; // Accuracy level
if (n == 0)
return 0;
while ((x - y) > e)
{
x = (x + y) / 2;
if (n == 0 || x == 0)
return 0;
y = n / x;
}
return x;
}
What is the time complexity of this?