简体   繁体   English

B+树删除

[英]B+ tree deletion

So I have this B+ tree:所以我有这个 B+ 树:在此处输入图像描述

I have to delete 49 here.我必须在这里删除 49。 How do I go about it?我该怎么做 go 呢?

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).删除 49 后,将 48 合并到包含 32 和 40 的邻居节点中。我们最终得到叶节点 (32, 40, 48)。
  2. After merging, update its parent node from (45) to (32).合并后,将其父节点从(45)更新为(32)。
  3. Since the node (32) only has 1 pointer, it can be eliminated.由于节点(32)只有1个指针,所以可以将其剔除。

Hence, we end up with root node (32)--->(32,40,48) on the right sub-tree of the root.因此,我们最终在根的右子树上得到根节点 (32)--->(32,40,48)。

In-depth explanation:深入解释:

There are 3 cases for deleting a key.删除密钥有 3 种情况。 After deleting a key for node,删除节点的密钥后,

If node still contains more than floor((n+1)/2) keys:如果节点仍然包含多于 floor((n+1)/2) 个键:

  1. Simply delete the key.只需删除密钥。 No updates needed.无需更新。

If node contains less than floor((n+1)/2) keys:如果节点包含少于 floor((n+1)/2) 个键:

  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.如果相邻叶节点有备用密钥(即,给出一个密钥仍会导致其自身拥有多于 floor((n+1)/2) 个密钥),则向邻居借用一个密钥。
  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. ** 对于情况 2 和 3,请务必记住在借用或合并后更新父节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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