Skip to content

Add iterative implementation alongside recursive BinarySearch#7359

Open
Mudita-Singh wants to merge 6 commits intoTheAlgorithms:masterfrom
Mudita-Singh:add-iterative-binary-search
Open

Add iterative implementation alongside recursive BinarySearch#7359
Mudita-Singh wants to merge 6 commits intoTheAlgorithms:masterfrom
Mudita-Singh:add-iterative-binary-search

Conversation

@Mudita-Singh
Copy link
Copy Markdown

🧩 Description
Added an iterative implementation of Binary Search alongside the existing recursive approach.

🚀 Changes Made
Implemented findIterative method using an iterative approach
Maintains consistency with existing generic structure (T extends Comparable)
Uses bitwise shift (>>> 1) for midpoint calculation, consistent with existing implementation

✅ Benefits
Avoids recursion overhead
Uses constant space complexity O(1)
Helps beginners understand both approaches

🧪 Testing
Tested with sample inputs to ensure correctness.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.40%. Comparing base (9729e56) to head (1ffcdf7).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #7359   +/-   ##
=========================================
  Coverage     79.39%   79.40%           
- Complexity     7092     7095    +3     
=========================================
  Files           792      792           
  Lines         23226    23226           
  Branches       4568     4568           
=========================================
+ Hits          18441    18442    +1     
  Misses         4047     4047           
+ Partials        738      737    -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.

@Mudita-Singh
Copy link
Copy Markdown
Author

Added an iterative implementation of Binary Search alongside the existing recursive approach.

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.

2 participants