This week was full of ups and downs (I like it ;) ). I started practicing div 2 500 problems on TopCoder but after 2 days I was having loads of academic work pending and unfortunatley I had to give up my idea of solving 3 problems a day . But I didn't stop coding . Everyday I was learning new & exciting stuffs . I started learning python and C++ (OOPS part) I fell ill also(Now I am fit) .
One of my batch mate asked me about the working of the square root function I told him that it should behave like a standard function with some iteration by which it outputs the answer to a particular level of precision and then while learning python I came across Newton Raphson method to calculate square root of a given number . I was very excited to see such method .Its like -
suppose we want to calculate the sqrt of N -
1. Take a rough approximation of lets say x = N/2 (It can be taken anything but it is advised to make it close to the square root of N)
2. Iterate -
y = (x + N/x)/2
x = y
3. stop iterating when you reach to a particular level of precision lets say 0.00001
sqrt(N)
{
x = N/2
while(1)
{ y = (x+N/x)/2
if(abs(y-x)<0.00001)break
x = y
}
return x
}
Wondering whether if this is the method behind the built in function sqrt ... Gonna search for it .
Yesterday, I gave an online contest on Codechef which was conducted by IIIT Delhi's programming club and got 362nd rank .. All questions were easy but I could solve only 2/5 due to lack of Algorithmic knowledge .
Thanks for reading and keep coding !
One of my batch mate asked me about the working of the square root function I told him that it should behave like a standard function with some iteration by which it outputs the answer to a particular level of precision and then while learning python I came across Newton Raphson method to calculate square root of a given number . I was very excited to see such method .Its like -
suppose we want to calculate the sqrt of N -
1. Take a rough approximation of lets say x = N/2 (It can be taken anything but it is advised to make it close to the square root of N)
2. Iterate -
y = (x + N/x)/2
x = y
3. stop iterating when you reach to a particular level of precision lets say 0.00001
sqrt(N)
{
x = N/2
while(1)
{ y = (x+N/x)/2
if(abs(y-x)<0.00001)break
x = y
}
return x
}
Wondering whether if this is the method behind the built in function sqrt ... Gonna search for it .
Yesterday, I gave an online contest on Codechef which was conducted by IIIT Delhi's programming club and got 362nd rank .. All questions were easy but I could solve only 2/5 due to lack of Algorithmic knowledge .
Thanks for reading and keep coding !
No comments:
Post a Comment