c++ - I need a container that supports efficient random access and O(k) insertion and removal -


I have tried to ask it again, but by not providing the necessary information about my problem, I asked a different question Ended the tax

I implement a data structure which is a tree. Each node in this tree has an array / vector / (random access structure) which is with all its children, which can be many arbitrary. It is easy to insert / remove elements because we always double / divide the number of elements in this array.

The same is o (k) entry / means of deletion in this context. We have the k element and we add k to or delete k / 2 . The reconstruction of the entire data structure is still fine. A dynamic array (or vector ) works

The question-raising operation is the following. Sometimes we have "split" a node n for children, which means that we divide children into different nodes. The way we are constantly in the group is the most effective method for this division, I think that in the position of a pointer for each new node where there are children and how many (we say that every node k takes children). But again, the number of these children can change and should not affect its siblings (or worse, the whole tree), ie the time for execution of an assembly should be O (k) and hey (n) . how do we do it?

A simple but incompetent task will be around that every time we split a node, we "many" "small" dynamic arrays as "split parts" (with children) "code"

Each of the "boxes" is a random access structure.

alt text

If you are implementing the structure from the description given by the tree, it may be best to create a new data structure to duplicate your tree. Especially if you are already tracking indicators between nodes.

If I understand your statement, then your tree will have vector of node pointers of children in each node. When you need to split nodes, you can create each node that receives one segment of the vector of each child pointers, and the newly created nodes will be inserted into the node vector's original node.

For example:

N1-> N2-> (N3, N4, N5, N6, N7, N8) N2 divided into two nodes: N1-> and and N2_2-> (N6, n7, n8) with with N2_1-> (N3, N4, N5)

(Sorry, I do not know how to attract trees easily ...)

In this way, You are relinking the memory instead of just copying, and the entry will usually be logged. In addition, it gives proper representation of the tree structure in the code.

Edit an example to add:

Suppose we have N1-> more; N2-> (N3, n4, n5, n6, n7, n8) . If N1 is required to add new nodes, then only the effect on N1 node is: N1-> (N 2, N 9) - & gt; (N3, N4, N5, N6, N7, N8)

The structure of a node can be similar to this (very simplified):

< Pre> square node {vector & lt; Node *> children; Node * guardian; };

The big tree structure will be from many of these nodes which are all linked to a binary tree. To add nodes in one of the nodes on the tree, you can add items to the children member of that node only. And nothing is affected.


Comments