Skip to content

Commit 384df67

Browse files
committed
closest pair program
1 parent b75292c commit 384df67

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/main/java/com/thealgorithms/randomized/ClosestPair.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@
1212
import java.util.*;
1313

1414
class Point implements Comparable<Point> {
15-
double x, y;
15+
double x;
16+
double y;
1617

1718
// Constructor to initialize a point with x and y coordinates
1819
Point(double x, double y) {
1920
this.x = x;
2021
this.y = y;
2122
}
2223

23-
// Compare points based on x-coordinates (for sorting)
2424
public int compareTo(Point other) {
2525
return Double.compare(this.x, other.x);
2626
}
2727

28-
// Compute Euclidean distance between two points
2928
static double distance(Point p1, Point p2) {
3029
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
3130
}
@@ -44,7 +43,6 @@ private static double closestRecursiveHelper(List<Point> points, int left, int r
4443
//Base Case occurs with 3 or fewer points
4544
if (right - left <= 2) return baseCase(points, left, right);
4645

47-
4846
//Divide and conquer
4947
int mid = (left + right) / 2;
5048
double midX = points.get(mid).x;
@@ -72,7 +70,9 @@ private static double checkBoundary(List<Point> points, int left, int right, dou
7270
//Consider a boundary by the dividing line
7371
List<Point> boundary = new ArrayList<>();
7472
for (int i = left; i <= right; i++) {
75-
if (Math.abs(points.get(i).x - midX) < minDist) boundary.add(points.get(i));
73+
if (Math.abs(points.get(i).x - midX) < minDist) {
74+
boundary.add(points.get(i));
75+
}
7676
}
7777

7878
//sort by y coordinate within the boundary and check for closer points

0 commit comments

Comments
 (0)