简体   繁体   中英

B+ tree deletion

So I have this B+ tree:在此处输入图像描述

I have to delete 49 here. How do I go about it?

Will it be like this:在此处输入图像描述

Or like this? : 在此处输入图像描述

  1. After deleting 49, merge 48 into its neighbour node that is containing 32 and 40.We end up with leaf node (32, 40, 48).
  2. After merging, update its parent node from (45) to (32).
  3. Since the node (32) only has 1 pointer, it can be eliminated.

Hence, we end up with root node (32)--->(32,40,48) on the right sub-tree of the root.

In-depth explanation:

There are 3 cases for deleting a key. After deleting a key for node,

If node still contains more than floor((n+1)/2) keys:

  1. Simply delete the key. No updates needed.

If node contains less than floor((n+1)/2) keys:

  1. If neighbour leaf nodes have key to spare (ie giving out a key still results in itself having more than floor((n+1)/2) keys), borrow a key from neighbour.
  2. If neighbours unable to lend keys, merge current node with a neighbour node.

** For cases 2 and 3, always remember to update parent nodes after borrowing or merging.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM