I have tried again to ask the same question, but I ended up asking a different question by not providing essential information about my problem.
I implement a data structure which is a tree. Each node of this tree has an array/vector/(random access structure) with all its children which can be arbitrary many. The insertion/removal of elements is easy since we always double/divide-by-two the number of the elements in this array.
That is what the O(k)
insertion/removal means in this context. We have k
elements and we append k
more or delete k/2
. Rebuilding the whole data structure is fine so far. A dynamic array
(or a vector
) works.
The operation that raises the question is the following. Sometimes we have to "split"
a node having n
children, which means we "divide" the children among different nodes. The way we dive is in continuous groups. The most efficient way for this split is, I guess, to have one pointer for each new node at the position where its children are and how many there are (let's say each node takes k
children). But then, the number of these children may change and that should not affect its siblings (or even worse, the whole tree) i.e the execution time of an insertion should be O(k)
and not O(n)
. How do we do it?
An easy but inefficient work-around would be that every time we split a node, we replace the "big" array of children
with many (as many as the split parts) "small" dynamic arrays.
Each of the following "boxes" is a random access structure.