![]()
We may not get a chance to go over deleting items from B+ trees in class, so here is a review of the rules for insertion/deletion, and a couple of examples.
To insert a new value:
Follow the pointers down ntil you find where it should be in the leaf node.
If the leaf node has space, just insert the value and appropriate record pointer.
If the node is full (has n values), you must split
the node into 2 nodes.
a. Insert the new value in the correct order.
b. Split the old leaf node into 2 new nodes, with half (or half + 1) the
values in each node.
c. Adjust the old leaf node's parent index node to reflect the change by
inserting a new index value and pointers. Insert the last value in the new
left-hand node in the appropriate place in the parent node. If the parent
node still has space, this is easy, but note that the split could propagate
up the tree. If so, remember that a value occurs at most once in the
index structure. When you split an index node, bump the middle value up into
the next level, rather than copying it.
To delete a value:
Delete the value from the leaf node, and if it appeared in
one of the index nodes, delete it from there too. The only tricky part is if
deleting a value causes the number of values in the node to drop below the
lower threshhold, then you must readjust it and its neighboring nodes. There
are 2 options:
a. If either its right or left sibling has enough values so that they can be
split and still keep enough values in both nodes,
i. Redistribute the values accordingly, and
ii. Change the index value in the parent node so it is
the rightmost value of the left sibling.
b. If neither sibling has enough values, merge the node with a sibling. This
is the reverse of insertion.
i. Order the values in both nodes into one node, and
ii. Remove the index entry from the parent node. Note
that the merge could propagate up the tree.
Deletion Example:
Initial tree.

Delete 25, and adjust index.

Delete 911, and redistribute with sibling, adjust index.

Delete 217.
Delete 93.
Delete 413, merge, remove subtree, adjust index.

Delete 10, merge, remove subtree, collapse layer.

More Insertion Practice:
Start with a single node containing 49 and 53.
Add 71.
Add 77.
Add 85.
Add 64.
Your resulting tree should be:

![]()
© 2000 Sheila O. Denn, Stephanie Haas, Bradley M. Hemminger