The original description of the k-d tree recognized that rebalancing techniques, such as are used to build an AVL tree or a red-black tree, are not applicable to a k-d tree. Hence, in order to build a balanced k-d tree, it is necessary to find the median of the data for each recursive subdivision of those data. The sort or selection that is used to find the median for each subdivision strongly influences the computational complexity of building a k-d tree. This paper discusses an alternative algorithm that builds a balanced k-d tree by presorting the data in each of k dimensions prior to building the tree. It then preserves the order of these k sorts during tree construction and thereby avoids the requirement for any further sorting. Moreover, this algorithm is amenable to parallel execution via multiple threads. Compared to an algorithm that finds the median for each recursive subdivision, this presorting algorithm has equivalent performance for four dimensions and better performance for three or fewer dimensions.
翻译:k-d树的原始描述指出,诸如构建AVL树或红黑树时使用的再平衡技术不适用于k-d树。因此,为了构建平衡的k-d树,必须在数据的每个递归细分中找到数据的中位数。用于寻找每个细分中位数的排序或选择操作,极大地影响了构建k-d树的计算复杂度。本文讨论了一种替代算法,该算法通过在构建树之前对数据的k个维度分别进行预排序来构建平衡k-d树。随后,在树构建过程中保持这k个排序的顺序,从而避免了任何进一步的排序需求。此外,该算法适合通过多线程进行并行执行。与为每个递归细分寻找中位数的算法相比,这种预排序算法在四维情况下具有相当的性能,而在三维或更少维度下则表现更优。