Solving Riddle: Find Closest 2 Points on a Plane in O(N)

In summary, The conversation is about solving a riddle involving finding the two closest points on a plane. The person asking for help is aware of a "simple" solution that requires O(N * log^2(N)) and a more complex one that requires O(N * log(N)). They ask for any ideas or solutions and provide a hint about an arbitrary function. They later share a solution they found online.
  • #1
Atlas
5
0
Here's a riddle I'm having trouble solving:
There are N points on a plane. Find the two points that are closest, in time better than O(N^2).

Any idea?
Thanks :)
 
Mathematics news on Phys.org
  • #2
randomly pick point p. then choose point P+1... :-p
 
  • #3
Nice problem. Are you sure there is a solution? I'll think on it some more if you know that it can be solved (well, I'll think on it anyways).
 
  • #4
I know there's a so-called "simple" solution that requires O(N * log^2(N)), and a more complex one that requires O(N * log(N)).
 
  • #5
Here's a hint:

If the problem was "Given an arbitrary function f(P, Q) of two points, find the pair of points that minimizes f(P, Q)", can you prove that the best algorithm is Θ(n²)?
 

1. How do you approach solving this riddle?

To solve this riddle, you can use the brute force method, which involves checking the distance between every pair of points and finding the minimum distance. Alternatively, you can use a more efficient algorithm such as the divide and conquer approach.

2. What is the time complexity of solving this riddle?

The brute force method has a time complexity of O(N^2) as it involves checking the distance between every pair of points. The divide and conquer approach has a time complexity of O(NlogN) as it involves sorting the points and then finding the closest pair.

3. What is the space complexity of solving this riddle?

The brute force method has a space complexity of O(1) as it does not require any extra space. The divide and conquer approach has a space complexity of O(N) as it requires creating an array to store the sorted points.

4. Can this riddle be solved in linear time?

No, this riddle cannot be solved in linear time as the best possible time complexity for any algorithm is O(NlogN).

5. Is there a specific input format for this riddle?

Yes, the input should consist of a list of points in the form of (x, y) coordinates. The points can be represented as a 2D array or a list of tuples.

Similar threads

Replies
4
Views
616
Replies
2
Views
691
  • General Math
Replies
3
Views
879
Replies
2
Views
1K
  • General Math
Replies
1
Views
1K
Replies
2
Views
1K
Replies
36
Views
4K
Replies
1
Views
762
Back
Top