Algorithm for finding nearby points?

前端 未结 7 892
独厮守ぢ
独厮守ぢ 2021-01-30 18:19

Given a set of several million points with x,y coordinates, what is the algorithm of choice for quickly finding the top 1000 nearest points from a location? \"Quickly\" here mea

7条回答
  •  囚心锁ツ
    2021-01-30 18:54

    Quadtrees are nice, but BSP trees are guaranteed to run in O(log n) time. I think quadtrees require a finite bounding volume, and and there are some degenerate cases where quadtrees fail miserably, such as when a large number of points occupy the same relatively small space.

    That being said, Quadtrees are arguably easier to implement and quite effective in most common situations. It's what UPS uses in their routing algorithms, because it's drawbacks don't pose significant problems in practice, probably because cities tend to be spread out over the region of interest.

提交回复
热议问题