Added RandomizedClosestPair code and test#6224
Added RandomizedClosestPair code and test#6224Jivi-this-side wants to merge 1 commit intoTheAlgorithms:masterfrom
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6224 +/- ##
============================================
+ Coverage 73.81% 73.85% +0.03%
- Complexity 5311 5325 +14
============================================
Files 673 674 +1
Lines 18376 18421 +45
Branches 3553 3562 +9
============================================
+ Hits 13565 13604 +39
- Misses 4264 4267 +3
- Partials 547 550 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Thanks for contributing!
Please fix the pipeline (GitHub Actions) and adjust the requested changes so that the Checkstyle rules will pass. The rest looks pretty good to me 🙂 @Jivi-this-side
| } | ||
|
|
||
| public static class Point { | ||
| public final double x, y; |
There was a problem hiding this comment.
Each variable declaration must be in its own statement. Please split these two declarations.
| Point[] Qx = Arrays.copyOfRange(px, 0, mid); | ||
| Point[] Rx = Arrays.copyOfRange(px, mid, n); | ||
|
|
||
| List<Point> Qy = new ArrayList<>(); | ||
| List<Point> Ry = new ArrayList<>(); |
There was a problem hiding this comment.
please write qx instead of Qx because this is not camelCase.
| if (p.x <= midPoint.x) Qy.add(p); | ||
| else Ry.add(p); |
There was a problem hiding this comment.
'if' construct must use '{}'s (see checktyle)
| private static double distance(Point p1, Point p2) { | ||
| return Math.hypot(p1.x - p2.x, p1.y - p2.y); | ||
| } | ||
| } |
There was a problem hiding this comment.
Line has trailing spaces according to checkstyle, please remove this
| double result = RandomizedClosestPair.findClosestPairDistance(points); | ||
| assertEquals(5.0, result, 0.00001); | ||
| } | ||
| } |
There was a problem hiding this comment.
Line has trailing spaces according to checkstyle, please remove this
|
So, how is it going? @Jivi-this-side |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution! |
|
Please reopen this pull request once you have made the required changes. If you need help, feel free to ask in our Discord server or ping one of the maintainers here. Thank you for your contribution! |
clang-format -i --style=file path/to/your/file.javaRandomized Closest Pair of Points : (As per issue #6219 added this algo to repo)
The Closest Pair of Points problem finds the minimum Euclidean distance between two points in a 2D plane.
Randomized Algorithm Approach:
Randomly shuffle the input points.
Use a sweep-line + grid bucketing strategy to maintain only nearby points for efficient lookup.
Continuously update the closest pair distance while sweeping from left to right.
⚡ Time Complexity
Expected Time: O(n)
Worst-case Time: O(n log n)
Use Cases
Geospatial clustering
Nearest-neighbor search
Computational geometry in games, simulations, and robotics
Thank you!