Predict the required number of pre-distributed nodes in the kD tree

I implement dynamic kD-Tree in an array view (keeping nodes in std :: vector) with a wide range. Each inth non-leaf node has a left child in (i<<1)+1and a right child in (i<<1)+2. It will support incremental point insertion and score collection. However, I am faced with the problem of determining the necessary number of possible nodes for the gradual preliminary allocation of space.

I found a formula on the Internet that seems to be wrong:

N = min (m - 1, 2n - ½m - 1),

where m is the least power of 2 greater than or equal to n, the number of points.

My execution of the formula is as follows:

size_t required(size_t n)
{
    size_t m = nextPowerOf2(n);
    return min(m - 1, (n<<1) - (m>>1) - 1);
}
Function

nextPowerOf2 , 2 n

.

+4
1

node kd- . , kd- , :

1) ( , x1 x2, x3 = (x1 + x2)/2), : i) node, ii) node .

, . | X |, kd- , log | X | * n (, log | X | * n - n log n + 2n) . , : , , . log | X | , log | X | , log n, log | X | .

2) , , node ( ) . , - n. , , (, X, O (n). , (1) O (log | X |)).

+1

All Articles