Yea Dave .. I was actually looking for your response.. Coz it generally
have some mathematical background. So, Could U provide us some least
Complexity Algo for this same old general and basic problem.


On Thu, Feb 7, 2013 at 11:08 AM, Dave <dave_and_da...@juno.com> wrote:

> @Gaurav: Does it work for n = 25 or for n = 8? I think you've confused
> "perfect square" with "power of two."
>
> Dave
>
> On Wednesday, February 6, 2013 11:32:55 PM UTC-6, Gaurav Rana wrote:
>
>> if(n&(n-1)==0)
>> //perfect square
>>
>>
>> On Thu, Feb 7, 2013 at 3:01 AM, Don <dond...@gmail.com> wrote:
>>
>>> The following is a bit faster than the Newton's Method solution I
>>> suggest above. It uses a binary square root algorithm as seen here:
>>> http://en.wikipedia.org/wiki/**Methods_of_computing_square_**
>>> roots#Binary_numeral_system_.**28base_2.29<http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Binary_numeral_system_.28base_2.29>
>>> The value is a perfect square if x ends up being zero.
>>>
>>> bool isSqr(unsigned int x)
>>> {
>>>    unsigned int res = 0;
>>>    unsigned int bit = 1 << 30;
>>>    while(bit > x) bit >>= 2;
>>>    while(bit)
>>>    {
>>>       if (x >= res + bit)
>>>       {
>>>          x -= res + bit;
>>>          res = (res >> 1) + bit;
>>>       }
>>>       else
>>>       {
>>>          res >>= 1;
>>>       }
>>>       bit >>= 2;
>>>    }
>>>    return (x == 0);
>>> }
>>>
>>> On Dec 23 2012, 10:37 am, Anil Sharma <anilsharmau...@gmail.com>
>>> wrote:
>>> > please suggest some efficient solution to check perfect square
>>> condition .
>>> > no matter how much large number is... eg..i/p-8949 o/p-93
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+...@**googlegroups.com.
>>>
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>> .
>>>
>>>
>>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to