[Paper Review] Building a Balanced k-d Tree in O(kn log n) Time
This paper presents a novel algorithm to build a balanced k-d tree in O(kn log n) time by presorting data along each of the k dimensions upfront and maintaining sorted order during tree construction. Unlike median-finding approaches, this method avoids repeated sorting, enabling efficient parallelization and outperforming traditional methods in low-dimensional spaces (≤3D), with equivalent performance in 4D.
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.
Motivation & Objective
- Address the inefficiency of median-finding algorithms in k-d tree construction, especially in low-dimensional spaces.
- Overcome the limitation that rebalancing techniques from binary search trees (e.g., AVL, red-black) do not apply to k-d trees.
- Develop a method that maintains data order across dimensions to eliminate repeated sorting during recursive subdivision.
- Enable efficient parallel execution by decoupling sorting from tree construction.
- Achieve optimal time complexity O(kn log n) while improving practical performance for k ≤ 3.
Proposed method
- Presort the input data along each of the k dimensions prior to tree construction.
- Maintain the sorted order of data points across all k dimensions throughout the recursive partitioning process.
- Use the median of the presorted data at each recursive level to split the dataset, avoiding repeated selection or sorting.
- Leverage the pre-sorted structure to extract median and partition points in O(1) time per level using index tracking.
- Design data structures that preserve sorted order and support efficient splitting and traversal.
- Support parallel execution by allowing independent processing of subtrees once the initial presorting is complete.
Experimental results
Research questions
- RQ1Can k-d tree construction be accelerated by eliminating repeated median-finding operations?
- RQ2Does presorting data along each dimension lead to better asymptotic and practical performance compared to median-finding per recursive call?
- RQ3Can the proposed method achieve O(kn log n) time complexity while being more efficient than existing approaches in low-dimensional settings?
- RQ4To what extent can the algorithm be parallelized due to the decoupling of sorting and tree building?
- RQ5How does the performance of the presorting-based method compare to median-finding methods in terms of constant factors for k = 2, 3, and 4?
Key findings
- The proposed algorithm achieves O(kn log n) time complexity for building a balanced k-d tree, matching the theoretical bound of median-finding methods.
- For k ≤ 3 dimensions, the presorting method outperforms median-finding algorithms due to reduced constant factors and better memory access patterns.
- In 4 dimensions, the performance of the presorting method is equivalent to that of median-finding approaches.
- The algorithm is amenable to parallelization because sorting is done once before tree construction, allowing independent subtree processing.
- The method avoids the overhead of repeated selection or sorting at each recursive level, significantly improving cache efficiency.
- Empirical results from the paper's implementation confirm superior performance in 2D and 3D, with measurable speedups in practice.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.