Add RandomizedClosestPair Algorithm and Unit Tests by aditya-7562 · Pull Request #6339 · TheAlgorithms/Java · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Add RandomizedClosestPair Algorithm and Unit Tests #6339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

aditya-7562
Copy link
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
Copy link

codecov-commenter commented Jul 4, 2025

Codecov Report

Attention: 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).

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
Copy link
Contributor Author

aditya-7562 commented Jul 4, 2025

👋 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! 🙏

Copy link
Member

@siriak siriak left a comment

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
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

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.