Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added RandomizedClosestPair code and test#6224

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Jivi-this-side wants to merge1 commit intoTheAlgorithms:master
base:master
Choose a base branch
Loading
fromJivi-this-side:closest-pair-distance-random-algo

Conversation

Jivi-this-side
Copy link

@Jivi-this-sideJivi-this-side commentedApr 17, 2025
edited
Loading

  • I have readCONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted withclang-format -i --style=file path/to/your/file.java

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

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is91.11111% with4 lines in your changes missing coverage. Please review.

Project coverage is 73.85%. Comparing base(ad5e496) to head(f111af6).

Files with missing linesPatch %Lines
...healgorithms/randomized/RandomizedClosestPair.java91.11%3 Missing and 1 partial⚠️
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.
📢 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.

Copy link
Collaborator

@DenizAltunkapanDenizAltunkapan left a comment
edited
Loading

Choose a reason for hiding this comment

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

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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Each variable declaration must be in its own statement. Please split these two declarations.

Comment on lines +59 to +63
Point[] Qx = Arrays.copyOfRange(px, 0, mid);
Point[] Rx = Arrays.copyOfRange(px, mid, n);

List<Point> Qy = new ArrayList<>();
List<Point> Ry = new ArrayList<>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

please write qx instead of Qx because this is not camelCase.

Comment on lines +65 to +66
if (p.x <= midPoint.x) Qy.add(p);
else Ry.add(p);
Copy link
Collaborator

Choose a reason for hiding this comment

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

'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);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line has trailing spaces according to checkstyle, please remove this

double result = RandomizedClosestPair.findClosestPairDistance(points);
assertEquals(5.0, result, 0.00001);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line has trailing spaces according to checkstyle, please remove this

@DenizAltunkapan
Copy link
Collaborator

So, how is it going?@Jivi-this-side

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@DenizAltunkapanDenizAltunkapanDenizAltunkapan requested changes

@yanglbmeyanglbmeAwaiting requested review from yanglbmeyanglbme is a code owner

@vil02vil02Awaiting requested review from vil02vil02 is a code owner

@BamaCharanChhandogiBamaCharanChhandogiAwaiting requested review from BamaCharanChhandogiBamaCharanChhandogi is a code owner

@alxkmalxkmAwaiting requested review from alxkmalxkm is a code owner

@siriaksiriakAwaiting requested review from siriaksiriak is a code owner

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@Jivi-this-side@codecov-commenter@DenizAltunkapan

[8]ページ先頭

©2009-2025 Movatter.jp