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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy