There are three cases to consider when deleting a key from a BTree:
We now recursively apply the delete function to the parent. One of the three cases considered thus far for the leaves will apply to the parent:
As a final example, suppose we delete the root M from the last example tree shown in the BTree notes. The smallest key in M's right subtree is N, so we replace M with N. This leaves NP with only 1 key, P. P's right sibling cannot spare a key, so we must merge P with ST. This also requires that the parent of P and ST, R, be moved into the merged leaf, producing the leaf PRST:
N
----------------
| |
F J U
------------ ---------
| | | | |
ABDE GI KL PRST XZ
U's node now does not have the minimum required number of keys and its
left sibling, FJ, cannot spare one. Hence we merge FJ with U and include
their parent, N, in the merged node. The new node contains the keys FJNU.
We now have a tree with one less level:
-------------------------
| F J N U |
-------------------------
/ | | | \
| | | | |
ABDE GI KL PRST XZ