Python icon indicating copy to clipboard operation
Python copied to clipboard

about `closest_pair_of_points.py`

Open Pokryton opened this issue 2 years ago • 1 comments

What would you like to share?

Firstly, i think there is apparently a typo in line 107:

https://github.com/TheAlgorithms/Python/blob/17059b7ece0e9b2aa0f6e1789d635d6c3eef93ca/divide_and_conquer/closest_pair_of_points.py#L103-L109

The first argument should be points_sorted_on_x rather than points_sorted_on_y.

Then, IMHO, the points_sorted_on_x should be divided into 2 parts too. Otherwise, following part of the algorithm will always take $\Theta(n)$ time in each recursive calls to closest_pair_of_points_sqr , and the total complexity will be $O(n^2)$ then.

https://github.com/TheAlgorithms/Python/blob/17059b7ece0e9b2aa0f6e1789d635d6c3eef93ca/divide_and_conquer/closest_pair_of_points.py#L116-L119

Additional information

No response

Pokryton avatar Oct 24 '23 13:10 Pokryton

you are right. there appears to be a typo in the code snippet you provided. The first argument in the second call to closest_pair_of_points_sqr should be points_sorted_on_x rather than points_sorted_on_y.

In the divide-and-conquer algorithm for finding the closest pair of points, the points_sorted_on_x should also be divided into two parts when splitting the points. this a good way to reduce time complexity of the algo.

fredlee-al avatar Oct 28 '23 03:10 fredlee-al