Re: Fwd: [algogeeks] Re: recursive nearest square

2011-08-09 Thread Ankuj Gupta
My bad but it can be made recursive :) On Aug 9, 8:17 pm, Dave wrote: > @Ankuj: Yeah, but he asked for it to be recursive. Yours is iterative. > > Dave > > On Aug 9, 9:56 am, Ankuj Gupta wrote: > > > > > > > > > we can do it in logn by using binary search approach found > > n is the number w

Re: Fwd: [algogeeks] Re: recursive nearest square

2011-08-09 Thread Dave
@Ankuj: Yeah, but he asked for it to be recursive. Yours is iterative. Dave On Aug 9, 9:56 am, Ankuj Gupta 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; >         if(n==0) >      

Re: Fwd: [algogeeks] Re: recursive nearest square

2011-08-09 Thread Ankuj Gupta
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;

Fwd: [algogeeks] Re: recursive nearest square

2011-08-09 Thread Nikhil Veliath
@dave:Ma mistake should have been nearest square root :) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@goo

[algogeeks] Re: recursive nearest square

2011-08-07 Thread Venkat
Find_Nearest(i , prev , n) { int sqr=n*n; if(sqr > i) { if((sqr-i)>(i-prev)) return sqr ; else return prev; } Find_Nearest(i,sqr,n+1); } initial call value : Find_Nearest(27, 0, 1); prev= previous square value. Thanks Venkat http://cloud-computation.blogspot.com/ On Aug 7

[algogeeks] Re: recursive nearest square

2011-08-07 Thread Dave
@Nikhil: Your example shows a strange use of the phrase "nearest square". It would seem that the nearest square to 27 would be 25, not sqrt(25). But anyway If n = 0 return 0 Else recursively find k = the nearest square to n/4 return 2*k-1, 2*k, or 2*k+1, whichever one squared is closer to

[algogeeks] Re: recursive nearest square

2011-08-07 Thread SVIX
why recursive? On Aug 7, 7:41 am, Nikhil Veliath wrote: > write a recursive code to print the nearest square of a number > > eg if no is 27 > > the nearest square is 5 > > it should also take care of large nos... -- You received this message because you are subscribed to the Google Grou