What is the fastest way to find the closest point to a given point?

后端 未结 9 2152
情歌与酒
情歌与酒 2020-11-28 07:18

What is the fastest way to find closest point to the given point in data array?

For example, suppose I have an array A of 3D points (with coordinates x,

9条回答
  •  余生分开走
    2020-11-28 07:28

    I would use a KD-tree to do this in O(log(n)) time, assuming the points are randomly distributed or you have a way to keep the tree balanced.

    http://en.wikipedia.org/wiki/Kd-tree

    KD trees are excellent for this kind of spatial query, and even allow you to retrieve the nearest k neighbors to a query point.

提交回复
热议问题