0

For spatial queries like nearest neighbor search, in theory, KD tree or Voronoi or R tree(or one of its variants) work. But what is the preferred data structure/algo for dynamic data?

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73
mithya
  • 363
  • 1
  • 10

2 Answers2

1

It depends on your actual update rate. There is a big difference if 1% of your data changes every hour, or 90% change every tick, as common in computer games.

kd-trees are not very robust to updates - you can insert at acceptable cost, but deletions are commonly handled with tombstones, and you will need to frequently rebuilt the tree. They are not very efficient to store on disk. For computer games, it may be viable to rebuild a kd-tree every tick instead of doing any updates at all.

Quadtrees and other grid-based structures should be fine, in particular if you know your data cannot concentrate infinitely (e.g. because you ensure minimum distances before).

R-trees are a good balance, in particular if you want to persist your data. This structure is designed for updates, and tries to keep changes local. Only if a page overflows or underflows it needs to be split. There also exist improvements that keep change lists, so they can further delay updates to the tree; this is interesting to increase throughput.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
0

You can compute the bounds and simply use a linked list or an array/loop. It's also very fast slower runtime but cheaper build cost.

Micromega
  • 12,486
  • 7
  • 35
  • 72