在2-3-4 Tree中插入时如何拆分节点?

时间:2017-02-17 10:20:04

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

是否有关于如何在2-3-4树中拆分节点的规则?

E.g。如果我将3,7,4,9插入2-3-4树:

它会像这样(黄色)或那个(绿色)分开,如下所示:

enter image description here

两者都有效吗?

1 个答案:

答案 0 :(得分:2)

绿色。您需要考虑算法步骤。查看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.