2017-02-17 124 views

回答

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. 
+0

但是在2-3樹的情況下,我們在插入值後分割。所以,中間成爲根值。那麼,在4節點的情況下會有所不同? – user963241

+0

使用2-3樹時,處理3節點時有2個值,因此沒有中間值。這不是2-3-4棵樹的花瓶。我實際上已經看到了一些算法插入值然後拆分爲2-3-4樹,因此它看起來像**都是有效的。** – gms0ulman

+0

實際上[另一種方法](https://www.cs.umd。 edu/class/summer2016/cmsc132/lectures/Lecture17_2_3_4_tree.pdf)也在**插入之前使用了split **。 – gms0ulman