Give a very good method to count the number of ones in a "n"
(e.g. 32) bit number.
Answer Posted / manish kumar
for (c = 0; n; c++)
n &= n - 1;
Result: the value of c.
complexity:o(logn)
Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Can I create my own functions in c++?
What is static class data?
What is type of 'this' pointer?
which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?
What is a container class?
What is conditions when using boolean operators?
What is c++ and its uses?
Is it possible to get the source code back from binary file?
Can you sort a set c++?
what kind of projects are suitable for c and c++
What is stack unwinding?
Assume an array of structure is in order by studentID field of the record, where student IDs go from 101 to 500. Write the most efficient pseudocode algorithm you can to find the record with a specific studentID if every single student ID from 101 to 500 is used and the array has 400 elements. Write the most efficient pseudocode algorithm you can to find a record with a studentID near the end of the IDs, say in the range from 450 to 500, if not every single student ID in the range of 101 to 500 is used and the array size is only 300
How do we balance an AVL Tree in C++?
List down the guideline that should be followed while using friend function.
What does h mean in maths?