插入2-3-4树时如何拆分节点?

How to split node when inserting in 2-3-4 Tree?

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

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

它会像这样(黄色)还是那样(绿色)拆分,如下所示:

两者都有效吗?

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