Skip to content

Fix bugs and typo errors in closest_pair_of_points.py #14355

Open
Roy027 wants to merge 17 commits intoTheAlgorithms:masterfrom
Roy027:master
Open

Fix bugs and typo errors in closest_pair_of_points.py #14355
Roy027 wants to merge 17 commits intoTheAlgorithms:masterfrom
Roy027:master

Conversation

@Roy027
Copy link

@Roy027 Roy027 commented Mar 9, 2026

Describe your change:

  • Add an algorithm
  • Fix a bug or typo in an existing algorithm
  • Add or change doctests
  • Documentation change

Summary

This PR fixes several logic errors in divide_and_conquer/closest_pair_of_points.py.

The strip search loop previously skipped valid comparisons due to incorrect
loop bounds. The recursive call also passed an incorrect sorted list,
breaking the divide-and-conquer step of the algorithm.

The doctest for dis_between_closest_in_strip() previously expected 85,
which only occurred because the buggy implementation skipped valid point
comparisons. After fixing the logic, the correct result is 5.

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file.
  • All functions and variable names follow Python naming conventions.
  • All functions and variable names follow Python naming conventions. (Checked: Added type hints)
  • All functions have doctests that pass the automated testing.

Roy027 and others added 16 commits September 27, 2021 00:39
There are typo errors in closest_pair_points function and errors in dis_between_closest_in_strip function.
There are typo errors in closest_pair_points function and errors in dis_between_closest_in_strip function.
There are typo errors in closest_pair_points function and errors in dis_between_closest_in_strip function.
There are typo errors in closest_pair_points function and errors in dis_between_closest_in_strip function.
Fix bugs and typo errors in closest pair of points
Summary
This pull request addresses critical logic errors and typos in the
closest_pair_of_points.py
 algorithm. These fixes ensure the algorithm produces mathematically correct results and passes all automated tests.

Key Fixes:
Loop Logic Correction: In
dis_between_closest_in_strip
, the search loop was modified to correctly check all necessary pairs within the strip optimization.
Recursion Parameter Fix: Corrected a typo in
closest_pair_of_points_sqr
 where the X-sorted list was not being correctly partitioned for recursive calls.
Doctest Alignment: Updated the doctest in
dis_between_closest_in_strip
 from 85 to 5 to reflect the correct mathematical result after the logic fix. The previous expected value of 85 was a result of the bugged implementation.
@algorithms-keeper algorithms-keeper bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Mar 9, 2026
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Mar 9, 2026
@Roy027
Copy link
Author

Roy027 commented Mar 9, 2026

sorry accidentally modified DIRECTORY.md but i have removed changes.

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

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files tests are failing Do not merge until tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant