Skip to content

Commit 4174a84

Browse files
authored
Update README.markdown
1 parent a018f72 commit 4174a84

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Closest Pair/README.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Closest Pair is an algorithm that finds the closest pair of a given array of points By utilizing the Divide and Conquer methodology of solving problems so that it reaches the correct solution with O(nlogn) complexity.
44

5-
![Given points and we're required to find the two red ones](../Images/1200px-Closest_pair_of_points.png)
5+
![Given points and we're required to find the two red ones](Images/1200px-Closest_pair_of_points.png)
66

77
As we see in the above image there are an array of points and we need to find the closest two, But how do we do that without having to compare each two points which results in a whopping O(n^2) complexity?
88

@@ -26,7 +26,7 @@ let line:Double = (p[mid].x + p[mid+1].x)/2
2626

2727
and just recursively calls itself until it reaches the base case we don't detect those points.
2828

29-
![ Points lying near the division line](Closest Pair/Images/Case.png)
29+
![ Points lying near the division line](Images/Case.png)
3030

3131
- To solve this we start by sorting the array on the Y-axis to get the points in their natural order and then we start getting the difference between the X position of the point and the line we drew to divide and if it is less than the min we got so far from the recursion we add it to the strip
3232

@@ -46,7 +46,7 @@ while i<n
4646

4747
- After you insert the points that could possibly give you a better min distance we get to another observation in the image below.
4848

49-
![The strip with 4 points shown](Closest Pair/Images/Strip.png)
49+
![The strip with 4 points shown](Images/Strip.png)
5050

5151
- Searching the strip is a brute force loop (But doesn't that just destroy everything we did? You ask) but it has an advantage it could never iterate on more than 8 points (worst case).
5252

0 commit comments

Comments
 (0)