【问题标题】:How to split node when inserting in 2-3-4 Tree?插入2-3-4树时如何拆分节点?
【发布时间】:2017-02-17 10:20:04
【问题描述】:

2-3-4树中的节点如何分割有规则吗?

例如如果我将 3、7、4、9 插入到 2-3-4 树中:

会像这里所示的那样(黄色)还是那样(绿色)分割:

都有效吗?

【问题讨论】:

    标签: algorithm tree insertion multiway-tree 2-3-4-tree


    【解决方案1】:

    绿色。您需要考虑算法步骤。查看the wikipedia page 了解插入步骤。关键部分是在考虑下一个插入之前通过将中间值上移一级来拆分一个 4 节点(有 3 个值)。

    1. Insert 3 into blank. Result: 3         (a 2-node)
    2. Insert 7.            Result: 3 - 7     (a 3-node)
    3. Insert 4.            Result: 3 - 4 - 7 (a 4-node)
    5. Insert 9. There is already a 4-node, so this must be split.
       The split will be to move 4 up a level, and 3 and 7 are now child nodes of 4
       (like your green diagram). 9 is then added next to the 7.
    

    【讨论】:

    • 但是在 2-3 棵树的情况下,我们在插入值后拆分。因此,中间成为根值。那么,在 4 节点的情况下会有所不同吗?
    • 对于 2-3 树,处理 3 节点时有 2 值,因此没有中间值。这不是有 2-3-4 棵树的花瓶。我实际上已经看到了一些插入值然后拆分为 2-3-4 树的算法,因此看起来 两者都是有效的。
    • 其实the other method也用了split before insert。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-06
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    相关资源
    最近更新 更多