Skip to content

Conversation

@Navadeep0007
Copy link
Contributor

Closes #6931

Description

Implemented algorithm to count total set bits from 1 to N using bit manipulation.

Changes

  • Added CountSetBits.java with optimized O(log n) solution
  • Added CountSetBitsTest.java with comprehensive test cases
  • Included both optimized and naive approaches for comparison

Algorithm Explanation

Uses mathematical approach to count set bits efficiently by:

  1. Finding the most significant bit position
  2. Counting bits at that position
  3. Recursively counting remaining bits

Time Complexity: O(log n)
Space Complexity: O(log n) for recursion stack

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2025

Codecov Report

❌ Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.35%. Comparing base (3979e82) to head (0ab23dc).

Files with missing lines Patch % Lines
...om/thealgorithms/bitmanipulation/CountSetBits.java 89.47% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7072      +/-   ##
============================================
- Coverage     78.36%   78.35%   -0.01%     
- Complexity     6690     6691       +1     
============================================
  Files           756      756              
  Lines         22208    22212       +4     
  Branches       4363     4363              
============================================
+ Hits          17403    17405       +2     
- Misses         4106     4107       +1     
- Partials        699      700       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Navadeep0007
Copy link
Contributor Author

@DenizAltunkapan could you please review into my PR,
I appreciate your efforts!

Copy link
Member

@DenizAltunkapan DenizAltunkapan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @Navadeep0007

@DenizAltunkapan DenizAltunkapan merged commit 9381161 into TheAlgorithms:master Nov 16, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] Count Total Set Bits from 1 to N (Bit Manipulation)

3 participants