1
votes

Say that I have a sequence of key values to be inserted into a B-tree of any given order. After insertion of all the elements, I am performing a deletion operation on some of those elements. Does it always give an unique result (in the form of a B-tree) or it can it differ according to the deletion operation?

Quoted from wiki :

link:https://en.wikipedia.org/wiki/B-tree

Deletion from an internal node

Each element in an internal node acts as a separation value for two subtrees, therefore we need to find a replacement for separation. Note that the largest element in the left subtree is still less than the separator. Likewise, the smallest element in the right subtree is still greater than the separator. Both of those elements are in leaf nodes, and either one can be the new separator for the two subtrees. Algorithmically described below:

Choose a new separator (either the largest element in the left subtree or the smallest element in the right subtree), remove it from the leaf node it is in, and replace the element to be deleted with the new separator.

The previous step deleted an element (the new separator) from a leaf node. If that leaf node is now deficient (has fewer than the required number of nodes), then rebalance the tree starting from the leaf node.

I think according to the deletion operation it may vary because of the above lines quoted in bold letters. Am I right? help :)

1
It would help if you include a link to the wiki where you copied from.Lorenz Meyer
@LorenzMeyer link added. Thanks :)ViX28

1 Answers

3
votes

If your question is whether two B-trees that contain the exact same collection of key values will always have identical nodes, then the answer is No.

Note that this is also true for e.g. simple binary trees.

However, in the case of B-trees this can be more pronounced because B-trees are optimized for minimizing page changes and thus the need to write back to slow secondary storage.