Skip to content

Commit 1567b58

Browse files
authored
Update BrianKernighanAlgorithm.java
1 parent 5cf2203 commit 1567b58

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Others/BrianKernighanAlgorithm.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
*
99
* algorithm to count the number of set bits in a given number
1010
*
11-
* Subtraction of 1 from a number toggles all the bits (from
12-
* right to left) till the rightmost set bit(including the
11+
* Subtraction of 1 from a number toggles all the bits (from right to left) till the rightmost set bit(including the
1312
* rightmost set bit).
14-
* So if we subtract a number by 1 and do bitwise & with
15-
* itself i.e. (n & (n-1)), we unset the rightmost set bit.
13+
* So if we subtract a number by 1 and do bitwise & with itself i.e. (n & (n-1)), we unset the rightmost set bit.
1614
*
17-
* If we do n & (n-1) in a loop and count the no of times loop
18-
* executes we get the set bit count.
15+
* If we do n & (n-1) in a loop and count the no of times loop executes we get the set bit count.
1916
*
2017
*
2118
* Time Complexity: O(logn)

0 commit comments

Comments
 (0)