U can use binary search method

On Aug 30, 1:56 pm, Rajeev Kumar <rajeevprasa...@gmail.com> wrote:
> use Babylonian method(Efficient) algrithm..............
> Refer 
> :http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylo...
>
> public *void* getSquareRoot(double s) {
>   double Xn = 2.0;
>   double lastXn = 0.0;
>   while (Xn != lastXn) {
>    lastXn = Xn;
>    Xn = (Xn + s / Xn) / 2.0;
>   }
>   return Xn;
>  }
>
>
>
>
>
>
>
>
>
> On Tue, Aug 30, 2011 at 1:49 PM, Ankur Garg <ankurga...@gmail.com> wrote:
> > @techcoder
>
> > Making an array of 32768 or INT_MAX will make ur compiler cry
>
> > Also ur case doesnt handle the scenario where square root is a decimal
> > number
>
> > On Tue, Aug 30, 2011 at 1:35 PM, tech coder 
> > <techcoderonw...@gmail.com>wrote:
>
> >> the sqrt of 32 bit number can't be more than 16 bits.
>
> >> have an array of 2^16 elemnts wtih elemts 1 2 3 4 5 .... 32768 .
>
> >> now apply binary search
> >> i=a[mid]    where mid=(lower+upper)/2
>
> >> if(i*i==num)
> >> i is the sqrt
>
> >> increment lower and upper accordingly as we do in binary search
>
> >> so order is Ologn    where n=2^16
>
> >> On Tue, Aug 30, 2011 at 11:37 AM, Raghavan <its...@gmail.com> wrote:
>
> >>> how to design this logic effectively?
>
> >>> double squareRoot(int num){
>
> >>> }
>
> >>> --
> >>> Thanks and Regards,
> >>> Raghavan KL
>
> >>>  --
> >>> 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...@googlegroups.com.
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/algogeeks?hl=en.
>
> >>  --
> >> 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...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/algogeeks?hl=en.
>
> >  --
> > 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...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> Thank You
> Rajeev Kumar

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to