Skip to content

Commit 5cf2203

Browse files
authored
spacing improved
1 parent 8db4ef9 commit 5cf2203

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Others/BrianKernighanAlgorithm.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
* @author Nishita Aggarwal
66
*
77
* Brian Kernighan’s Algorithm
8+
*
89
* algorithm to count the number of set bits in a given number
10+
*
911
* Subtraction of 1 from a number toggles all the bits (from
1012
* right to left) till the rightmost set bit(including the
1113
* rightmost set bit).
1214
* So if we subtract a number by 1 and do bitwise & with
13-
* itself (n & (n-1)), we unset the rightmost set bit.
15+
* itself i.e. (n & (n-1)), we unset the rightmost set bit.
16+
*
1417
* If we do n & (n-1) in a loop and count the no of times loop
1518
* executes we get the set bit count.
16-
* Number of iterations of the loop is equal to the number of
17-
* set bits in a given integer.
19+
*
1820
*
1921
* Time Complexity: O(logn)
2022
*

0 commit comments

Comments
 (0)