tags:

views:

50

answers:

1

Let's say there is a B-tree of order 8. This means it can have 8 pointers and 7 elements. Say the letters A through G are stored in this B-tree. So this B-tree is just a single node containing 7 elements.

Then you try to insert J into the tree. There's no room, so you have to split the node and create a new root node. Which element gets promoted up into the root node?

+1  A: 

When you want to insert a new element in a full node (with 2*t - 1 keys)

  • you split it by choosing the median key of the node (the key that is the middle)
  • you generate the two new children with t-1 keys each (splitting it according to the previous key)
  • the median value remains in the father node
  • then you proceed by normal insertion algorithm, looking where you should place the new element.
Jack
According to your algorithm then, d would be in the root node? The book shows e as being in the root node.
Phenom
Basically, you would have 8 elements in your case (A B C D E F G J), so there are two "middle" elements. Any of them (D or E) will do. Jack's answer talks rather about the situation where you pre-split the node before inserting, that is also possible, though not necessary (it is possible to split nodes long before they are actually inserted to). So neither the book nor Jack are wrong.
jpalecek