we can do it in logn by using binary search approach found
n is the number whose square root has to be
if(n==1)
return 1;
if(n==0)
return 0;
int low=0,high=n/2,mid,temp;
while(1)
{
mid = (low+high)/2;
@Ankuj: Yeah, but he asked for it to be recursive. Yours is iterative.
Dave
On Aug 9, 9:56 am, Ankuj Gupta ankuj2...@gmail.com wrote:
we can do it in logn by using binary search approach found
n is the number whose square root has to be
if(n==1)
return 1;
My bad but it can be made recursive :)
On Aug 9, 8:17 pm, Dave dave_and_da...@juno.com wrote:
@Ankuj: Yeah, but he asked for it to be recursive. Yours is iterative.
Dave
On Aug 9, 9:56 am, Ankuj Gupta ankuj2...@gmail.com wrote:
we can do it in logn by using binary search