M
M
MPetukhov2014-08-13 11:14:03
Algorithms
MPetukhov, 2014-08-13 11:14:03

Algorithm for sorting an array of points in 3D space relative to a given one?

Greetings!
Is there a fast algorithm for sorting an array of points in 3D space with respect to a given one?
Given:
Point (x, y, z)
Array of points with coordinates
The task is to sort the array in ascending order of distance from the Point.
Added:
Will sorting by AB = |xb - xa| + |yb - ya| + |zb - za| right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
throughtheether, 2014-08-13
@MPetukhov

Is there a fast algorithm for sorting an array of points in 3D space with respect to a given one?
I don't know what you mean by "fast", but my considerations are:
1) determine the distance from each of the n points to the given one - O(n) (even Θ(n)). I don't see the potential for fundamental improvement here.
2) sort the array - O(n*logn) at best.
Total - O(n)+O(n*logn)=O(n*logn).
Another thing is that if the input data has a specific structure, then it is possible, with an appropriate approach, to lower (or try to lower) the "constants" of the O-notation and, accordingly, the execution time.

V
Vitaly Zheltyakov, 2014-08-13
@VitaZheltyakov

Calculate the distance to each point and sort however you like. Nothing complicated

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question