Skip to content

Commit 26ec9c1

Browse files
authored
Fix bugs and typo errors in closest pair of points
There are typo errors in closest_pair_points function and errors in dis_between_closest_in_strip function.
1 parent 5d02103 commit 26ec9c1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

divide_and_conquer/closest_pair_of_points.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def dis_between_closest_in_strip(points, points_counts, min_dis=float("inf")):
7373
85
7474
"""
7575

76-
for i in range(min(6, points_counts - 1), points_counts):
77-
for j in range(max(0, i - 6), i):
76+
for i in range(points_counts-1):
77+
for j in range(i+1, min(i + 6, points_counts)):
7878
current_dis = euclidean_distance_sqr(points[i], points[j])
7979
if current_dis < min_dis:
8080
min_dis = current_dis
@@ -101,10 +101,10 @@ def closest_pair_of_points_sqr(points_sorted_on_x, points_sorted_on_y, points_co
101101
# recursion
102102
mid = points_counts // 2
103103
closest_in_left = closest_pair_of_points_sqr(
104-
points_sorted_on_x, points_sorted_on_y[:mid], mid
104+
points_sorted_on_x[:mid], points_sorted_on_y, mid
105105
)
106106
closest_in_right = closest_pair_of_points_sqr(
107-
points_sorted_on_y, points_sorted_on_y[mid:], points_counts - mid
107+
points_sorted_on_x[mid:], points_sorted_on_y, points_counts - mid
108108
)
109109
closest_pair_dis = min(closest_in_left, closest_in_right)
110110

@@ -114,7 +114,7 @@ def closest_pair_of_points_sqr(points_sorted_on_x, points_sorted_on_y, points_co
114114
"""
115115

116116
cross_strip = []
117-
for point in points_sorted_on_x:
117+
for point in points_sorted_on_y:
118118
if abs(point[0] - points_sorted_on_x[mid][0]) < closest_pair_dis:
119119
cross_strip.append(point)
120120

0 commit comments

Comments
 (0)