2
$\begingroup$

I have a collection of vectors, let`s say $n$ vectors. I am trying to find an easy way to SORT these vectors in that way that after sorting of vectors $(V_1,V_2,...,V_n)$ the first vector $V_1$ and the last vector $V_n$ will be two furthest vectors. Next $V_{n-1}$ will be the second farthest vector from the $V_1$. $V_{n-2}$ will be the third furthest vector from the $V_1$...and so on. Is there a good algorithm or an easy way to achieve this?

$\endgroup$
2
  • $\begingroup$ perhaps I understand your question wrongly, but couldn't you just choose an arbitrary vector to be $V_1$, find the distances of all the other vectors to $V_1$ and then simply sort them according to their distances away from $V_1$? $\endgroup$ Commented Mar 23, 2013 at 12:02
  • $\begingroup$ Clarification is necessary--by two farthest vectors do you mean $\max_{i,j}||V_i - V_j||_2$? (Which may not even be a unique pair in general.) $\endgroup$
    – adam W
    Commented Mar 23, 2013 at 12:59

1 Answer 1

1
$\begingroup$

To find two furthest vectors, compute the convex hull and find needed two points on it, it is O(n log n) in summary.

$\endgroup$
8
  • $\begingroup$ $V_1$ is not known to begin with, so "choosing" $V_1$ is the question. $\endgroup$
    – adam W
    Commented Mar 23, 2013 at 12:45
  • $\begingroup$ Any vector can be $V_1$. $\endgroup$
    – gukoff
    Commented Mar 23, 2013 at 12:47
  • $\begingroup$ In the question, $V_1$ and $V_n$ are the (likely) unique pair that have the greatest distance. So $V_1$ here is not arbitrary. I do not see a better way than searching all pair distances to find them... $\endgroup$
    – adam W
    Commented Mar 23, 2013 at 12:54
  • $\begingroup$ Okay. Is the distance a metric? $\endgroup$
    – gukoff
    Commented Mar 23, 2013 at 13:03
  • $\begingroup$ If yes - edited a post. $\endgroup$
    – gukoff
    Commented Mar 23, 2013 at 13:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .