Algorithm to find points that are furthest apart — better than O(n^2)?

后端 未结 7 1192
半阙折子戏
半阙折子戏 2020-12-08 22:30

In my program, I have a set of points. For purposes of rescaling, I am searching for the two nodes that are furthest apart, and then computing a factor by which to multiply

7条回答
  •  余生分开走
    2020-12-08 23:05

    If you perform this query often but the points do not change much, you can perform precalculations that can speed things up.

    Each point can store the farthest point from it and recheck on every point addition if the new point is farther.

    When you query you just go thru all the points and look at their cached points.

    You end up with O(n) for new point entry and O(n) for farthest apart query.

提交回复
热议问题