0

I work on the tree where each node has N children.

In my case each node has a unique identifier. i want to deduce an identifier of father node from the child identifier.

So, we can add an information on child identifier to deduce that for example: if the father's node is "123", the child node is "123.3" and then we deduce that the father of (123.3) is "123". but there is a problem where we have a large tree, then a node identifier can be "12.3.4.1.2.4.5...", not be a good solution.

What would be the best approach to generate a child identifier with a simple number and then deduce the father identifier (considering that it is unique in the entire tree)?

4

1 に答える 1

2

How about encoding the path to the node as a binary, ternary, etc. (matching N) integer? For example, the binary digits of 14 are {1, 1, 1, 0} and this could represent a path of right -> right -> right -> left. Or for a ternary tree, the ternary digits of 33 are {1, 0, 2, 0} and this could represent middle -> left -> right -> left.

于 2012-10-03T09:37:58.570 に答える