duanjiyun7391 2012-06-27 11:56
浏览 32
已采纳

合适的树数据结构

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

  1. Parent node can have multiple children.
  2. Unique parent
  3. Tree structure is rarely changed, os it is ok to recreate than add/rearrange nodes.
  4. Two way traversal
  5. mainly interested in, find parent, find children, find a node with a unique id
  6. Every node has a unique id
  7. There might be only hundreds of nodes in total, so performance may not be big influence
  8. 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

  1. https://github.com/petar/GoLLRB
  2. http://www.stathat.com/src/treap

Please let know any additional information required.

  • 写回答

2条回答 默认 最新

  • dougezhua0017 2012-06-27 12:11
    关注

    Since there are only hundreds of nodes, just make the structure the same as you have described.

    • Each node has a unique reference to parent node.
    • Each node has a list of child node.
    • Each node has an id
    • There is a (external) map from id --> node. May not even necessary.

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 openwrt双栈NAT
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用