[algogeeks] Re: reverse all the bits in a unsigned integer

2007-03-21 Thread [EMAIL PROTECTED]
On Mar 21, 7:40 am, "hijkl" <[EMAIL PROTECTED]> wrote: > . How to reverse all the bits in a unsigned integer? an signed > integer (you have to keep the sign of the integer)? For an unsigned int, the following algorithm can be used (I believe you can find in in the "Hacker's Delight" book by H.War

[algogeeks] Re: find the closest common ancestor of node u and v?

2007-03-21 Thread aakash mandhar
There is a highly optimal O(n) solution available. 1) Find the depth at which each node is situated let them be du and dv respectively for u and v 2) Not bring u and v to the same depth. that is skip abs(du-dv) nodes from the greater depth node 3) Compare both nodes and do a (u=u->parent and v=v->

[algogeeks] Re: find the closest common ancestor of node u and v?

2007-03-21 Thread Karthik Singaram L
Find the longest common prefix in the path from the root to nodes u and v --~--~-~--~~~---~--~~ 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 un

[algogeeks] Re: count the 1 bits in integer

2007-03-21 Thread Karthik Singaram L
The standard link http://graphics.stanford.edu/~seander/bithacks.html --~--~-~--~~~---~--~~ 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 unsubs

[algogeeks] Re: print n bit numbers in binary format..

2007-03-21 Thread Balachander
int *p; void PrintallComb(int i) { int j=0; if(i == nBits) { for(j=0;jhttp://groups.google.com/group/algogeeks -~--~~~~--~~--~--~---

[algogeeks] Re: count the 1 bits in integer

2007-03-21 Thread stone
I have a simple method. Let hash[x]=count of 1 bits in x for 0<=x<2^16 So for any 32-bit integer x, the count of 1 bits is hash[x&0x] +hash[x>>16]. We can pre-calculate all hash[] value. On Mar 21, 1:24 pm, "hijkl" <[EMAIL PROTECTED]> wrote: > How to count the 1 bits in a integer? > int C

[algogeeks] Re: count the 1 bits in integer

2007-03-21 Thread Balachander
Hi,, Think the No of 1 bits can be found in o(k) where k is the no of bits set while((n & (n-1)) >= 0) { c++; n = n & (n-1); printf(">> n %d Cnt %d \n",n,c); if(!n) break; } printf("Cnt %d \n",c); --~--~-~--~~~---~--~