I am trying to insert 3 4s into an empty B-tree. t = 3. I tried some applets online but all thay do is insert 4 once and then just drop 4. Is it the way it has been implemented in CLRS as I did not completely understand their pseudocode.
Asked
Active
Viewed 364 times
-1
-
What specifically are you looking for: the result, or code to do the insertion? – templatetypedef Mar 06 '14 at 03:44
-
i am looking for the result. Suppose the tree only has 4 at its root. I want to add another 4 to the tree. what is the result? – user3386395 Mar 06 '14 at 04:00
-
Just do a standard insertion, pretending that the new 4 is, say, smaller than all the other 4's or bigger than all the other 4's. What do you get? – templatetypedef Mar 06 '14 at 04:03
1 Answers
0
When N has become 3 and you do the fourth insert, the root node has to be split, with at least N/2 nodes remaining in it and in each new leaf node. So the result must be a tree with 1 key in the root, and two leaves with 1 and 2 keys in them respectively, in either order depending on whether you regard a duplicate key as coming before or after the existing duplicates. Normally it would be after ...

user207421
- 305,947
- 44
- 307
- 483