简体   繁体   English

这棵B +树有效吗?

[英]Is this B+ Tree Valid?

In a B+ tree, can a non leaf node exist such that it's key value is deleted? 在B +树中,是否可以存在一个非叶节点,以便其键值被删除? What this means is that the B+ tree has a value in its intermediate non leaf node but not in any of its leaf nodes. 这意味着B +树在其中间非叶节点中具有一个值,但在其任何叶节点中均没有。

Consider the following structure. 考虑以下结构。 I came across this while studying B+ trees. 我在研究B +树时碰到了这个问题。 In this structure 13 is not a leaf node. 在该结构13中不是叶节点。 But it is a non leaf node. 但这是一个非叶节点。 (In fact it was deleted in the previous instructions. Link for the picture . In this link go to the bottom of the page) (实际上,它已在前面的说明中删除。 图片的链接。在此链接中,转到页面底部)

我不了解的树的图像

If yes then how come the data is deleted? 如果是,那么如何删除数据?

Is this a mistake or is there something I am missing? 这是一个错误还是我缺少什么?

The image you posted is valid. 您发布的图片有效。 The only data returned by this tree is what you find in the last row. 该树返回的唯一数据是您在最后一行中找到的数据。 Because 13 has been removed from the tree, it has been removed from the last row. 由于13已从树中删除,因此已从最后一行中删除。 The fact that 13 exists in a non-leaf node is of no consequence to your results, it is just there to be a comparable value when traversing down the tree. 非叶节点中存在13的事实与您的结果无关紧要,当遍历树时,它只有一个可比较的值。 In this case the tree would behave no differently if the 13 was changed to a 16 (based on the above convention). 在这种情况下,如果将13更改为16 (基于上述约定),则树的行为不会有所不同。

Douglas Fisher did a comprehensive video series on B+ trees, which can be easier to learn from than reading articles. 道格拉斯·费舍尔(Douglas Fisher)在B +树上做了一个完整的视频系列,与阅读文章相比,学习起来更容易。 Part 1 can be found here . 第1部分可以在这里找到。


Edit : My response in the comments was too long so I will put it here. 编辑 :我在评论中的回复太长,因此我将其放在此处。 Plus this is useful info. 另外,这是有用的信息。

If you are searching for a 12 , and reach the 13 , you will compare IS 12 < 13 or 13 <= 12 , the left is true, so you will traverse down to the left leaf. 如果要搜索12并达到13 ,则将比较IS 12 < 1313 <= 12 ,左边为true,因此您将向下遍历到左边的叶子。 This would have happened whether or not 13 was 16 , because this is also true 12 < 16 . 无论13是否为16都会发生这种情况,因为12 < 16也是如此。

If you are searching for 16 and reach the 13 you will compare IS 16 < 13 or 13 <= 16 , the right expression is true, so you will traverse down to the right leaf. 如果您要搜索16并达到13 ,则将比较IS 16 < 1313 <= 16 ,正确的表达式为true,因此您将遍历到右边的叶子。 Then you will find the value of 16 there. 然后,您将在那里找到16的值。

If you are searching for 13 (which doesn't exist) you will ask IS 13 < 13 or 13 <= 13 , the right expression is true, so you will traverse down to the right leaf and find that there is no 13 there and you will kick out at this point that 13 has no value. 如果要搜索13 (不存在),则会询问IS 13 < 1313 <= 13 ,正确的表达式为true,因此您将遍历到右边的叶子并发现那里没有13并且此时您将被踢出13没有价值。

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

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