Counting set bits in a number
Submitted by: AdministratorFirst version:
int CoutSetBits(int Num)
{
for(int count=0; Num; Num >>= 1)
{
if (Num & 1)
count++;
}
return count;
}
Optimized version:
int CoutSetBits(int Num)
{
for(int count =0; Num; count++)
{
Num &= Num -1;
}
}
Submitted by: Administrator
int CoutSetBits(int Num)
{
for(int count=0; Num; Num >>= 1)
{
if (Num & 1)
count++;
}
return count;
}
Optimized version:
int CoutSetBits(int Num)
{
for(int count =0; Num; count++)
{
Num &= Num -1;
}
}
Submitted by: Administrator
Read Online Programming Algorithms Job Interview Questions And Answers
Top Programming Algorithms Questions
☺ | How to find median of a BST? |
☺ | Define and describe an iterative process with general steps of flow chart? |
☺ | State recursion and its different types? |
☺ | What is ARCBALL? |
☺ | What are the two ways through which the Markov algorithm terminates? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |