Skip to content

Randomized closest 2 points algorithm #6251

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

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

bri-harris
Copy link

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

@codecov-commenter
Copy link

codecov-commenter commented May 30, 2025

Codecov Report

Attention: Patch coverage is 88.88889% with 5 lines in your changes missing coverage. Please review.

Project coverage is 74.09%. Comparing base (b3c2c7a) to head (20d0d31).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...java/com/thealgorithms/randomized/ClosestPair.java 88.88% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6251      +/-   ##
============================================
+ Coverage     73.98%   74.09%   +0.10%     
- Complexity     5346     5364      +18     
============================================
  Files           677      678       +1     
  Lines         18652    18697      +45     
  Branches       3621     3631      +10     
============================================
+ Hits          13800    13853      +53     
+ Misses         4294     4283      -11     
- Partials        558      561       +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.

@siriak
Copy link
Member

siriak commented Jun 1, 2025

@DenizAltunkapan could you take a look at infer?

@DenizAltunkapan
Copy link
Collaborator

@DenizAltunkapan could you take a look at infer?

Of course @siriak . I'll take a look, when i find time

@DenizAltunkapan
Copy link
Collaborator

The current build of facebook/infer is failing (see), which also causes our GitHub Actions workflow to fail. To temporarily stabilize our CI pipeline, I used the last known working commit. Once the upstream build is fixed, I will update our workflow to use the latest version again. I will open a new Pullrequest, when it's working again. 😄 @siriak @bri-harris

siriak
siriak previously approved these changes Jun 3, 2025
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!

Copy link
Collaborator

@DenizAltunkapan DenizAltunkapan left a comment

Choose a reason for hiding this comment

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

Could you please implement the requested changes? @bri-harris Thank you!

Copy link
Collaborator

@DenizAltunkapan DenizAltunkapan left a comment

Choose a reason for hiding this comment

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

Could you please check the requested changes and fix the failing pipeline? Thank you! @bri-harris

assertNotNull(closestPair[0]);
assertNotNull(closestPair[1]);

assertTrue((closestPair[0].equals(points.get(0)) && closestPair[1].equals(points.get(1))) || (closestPair[1].equals(points.get(0)) && closestPair[0].equals(points.get(1))));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure this test is correct? Because the .equals method is not overwritten in the Point class

assertNotNull(closestPair[0]);
assertNotNull(closestPair[1]);

assertTrue((closestPair[0].equals(points.get(0)) && closestPair[1].equals(points.get(1))) || (closestPair[1].equals(points.get(0)) && closestPair[0].equals(points.get(1))));
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you please refine and improve the test a bit? The likely cause of the NullPointer warning is that the analysis tool doesn't recognize assertNotNull() as a safe null check—assigning the value to a variable before asserting might help. Thats probably why infer is failing

}
}
}
grid.put(key, p);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think currently, only one point is stored per grid cell, overwriting any existing points. This can cause missed closest pairs when multiple points fall into the same cell. It is recommended to store a list of points per cell to ensure correctness...

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.

4 participants