Content-Length: 269326 | pFad | http://github.com/DiptamGit/Algorithms-in-Java/commit/1567b58a46c2a7f7d92af4e8cb0c712d78569a08

58 Update BrianKernighanAlgorithm.java · DiptamGit/Algorithms-in-Java@1567b58 · GitHub
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

Lines changed: 3 additions & 6 deletions
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)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/DiptamGit/Algorithms-in-Java/commit/1567b58a46c2a7f7d92af4e8cb0c712d78569a08

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy