Which is the most suitable tree data structure to model a hierarchical (containment relationship) content. My language is bit informal as I don’t have much theoretical background on these
- Parent node can have multiple children.
- Unique parent
- Tree structure is rarely changed, os it is ok to recreate than add/rearrange nodes.
- Two way traversal
- mainly interested in, find parent, find children, find a node with a unique id
- Every node has a unique id
- There might be only hundreds of nodes in total, so performance may not be big influence
- Persistence may be good to have, but not necessary as I plan to use it in memory after reading the data from DB.
My language of choice is go (golang), so available libraries are limited. Please give a recommendation without considering the language which best fit the above requirement.
http://godashboard.appspot.com/ lists some of the available tree libraries. Not sure about the quality and how active they are. I read god about
Please let know any additional information required.
Since there are only hundreds of nodes, just make the structure the same as you have described.
2 way traversal is possible, since parent and child nodes are know. Same for find parent and find child.
Find id can be done by traverse the whole tree, if no map. Or you can use the map to quickly find the node.
Add node is easy, since there is a list in each node. Rearrange is also easy, since you can just freely add/remove from list of child nodes and reassign the parent node.
I’m answering this question from a language-agnostic aspect. This is a tree structure without any limit, so implementation is not that popular.