views:

67

answers:

2

I'm sure most are familiar with the closest pair problem, but is there another alogrithm or a way to modify the current CP algorithm to get the next closest pair?

+1  A: 

Easy one, in O(n log(n)) :

  • find the closets pair (p1,p2) in O(n log(n))
  • compute all pairs with p1 or p2 (but not (p1,p2)) keep the closest one, let's call it E in O(n)
  • remove p1 and p2 in (1)
  • find the closets pair, compare it to E and keep the closest one, again in O(n log(n))

You now have the second closest one.

Loïc Février
Do you know if there is an efficient way to generalize this process so you can obtain the kth closest pair? Preferably in a way that is not O(n!)?
Tyler Murry
I wonder how you compute the fourth step in O(n) :)
Dimitris Andreou
@Dimitris : indeed, `O(n log(n))` of course......
Loïc Février
@Tyler : just do k times the processus, so `O(k.n.log(n))`
Loïc Février