Skip to content

Add RandomizedClosestPair Algorithm and Unit Tests - #6339

Merged
siriak merged 8 commits into
TheAlgorithms:masterfrom
aditya-7562:feature/reservoir-sampling-improvements
Jul 4, 2025
Merged

Add RandomizedClosestPair Algorithm and Unit Tests#6339
siriak merged 8 commits into
TheAlgorithms:masterfrom
aditya-7562:feature/reservoir-sampling-improvements

Conversation

@aditya-7562

Copy link
Copy Markdown
Contributor

Summary

Added Randomized Closest Pair of Points algorithm under the randomized category as per issue #6219.
This algorithm efficiently finds the minimum Euclidean distance between any two points in a 2D plane using a randomized divide-and-conquer approach.

Randomized Algorithm Approach

  • Randomly shuffle the input points to avoid worst-case input ordering.
  • Use a divide-and-conquer strategy by recursively splitting the point set.
  • Maintain sorted orders in both x and y dimensions to allow efficient scanning.
  • Construct a strip of points near the midline and examine only candidates within distance d.
  • Return the minimum distance found among all point pairs.

Time Complexity

  • Expected Time: O(n log n)
  • Worst-Case Time: O(n log n)

Use Cases

  • Geospatial clustering and mapping
  • Nearest-neighbour search in 2D space
  • Computational geometry in:
    • Robotics
    • Simulations
    • Computer graphics and game engines

Checklist

  • I have read CONTRIBUTING.md
  • This pull request is entirely my work (no plagiarism)
  • All filenames follow PascalCase convention
  • All function and variable names follow Java naming conventions
  • A reference to Wikipedia is included in the class-level Javadoc
  • Code has been formatted using:
    clang-format -i --style=file path/to/your/file.java

@codecov-commenter

codecov-commenter commented Jul 4, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.47826% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.41%. Comparing base (58ac54c) to head (88608f6).
⚠️ Report is 393 commits behind head on master.

Files with missing lines Patch % Lines
...healgorithms/randomized/RandomizedClosestPair.java 93.47% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6339      +/-   ##
============================================
+ Coverage     74.36%   74.41%   +0.04%     
- Complexity     5403     5419      +16     
============================================
  Files           680      681       +1     
  Lines         18842    18888      +46     
  Branches       3656     3665       +9     
============================================
+ Hits          14012    14055      +43     
- Misses         4274     4276       +2     
- Partials        556      557       +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.

@aditya-7562

aditya-7562 commented Jul 4, 2025

Copy link
Copy Markdown
Contributor Author

👋 Hi maintainers,

I wanted to clarify that this PR has multiple commits because I’m a first-time contributor to this repository and was learning the contribution and CI process along the way.

I’ve since cleaned up the implementation, removed the private constructor test due to CodeQL/Infer warnings, and ensured the code follows all formatting, naming, and coverage guidelines. The Infer job is currently failing due to an OCaml dependency conflict (camlzip = 1.12), which appears unrelated to the actual code changes.

All required tests pass, and the patch coverage is above 93%. Please let me know if you'd prefer that I squash the commits or make any other changes.

Thank you for your time and for maintaining this amazing repository! 🙏

@siriak siriak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, thanks for contributing!

@siriak
siriak enabled auto-merge (squash) July 4, 2025 10:19
@siriak
siriak merged commit d709317 into TheAlgorithms:master Jul 4, 2025
6 of 7 checks passed
@aditya-7562
aditya-7562 deleted the feature/reservoir-sampling-improvements branch July 4, 2025 13:49
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.

3 participants