简体   繁体   English

使用 B+ 树插入项目的正确和标准方法是什么?

[英]What is the correct and standard way to insert item using B+ tree?

The problem is there is a lots of differences answer of b+ tree, due to their different b+ tree algorithms.问题是 b+ 树的答案有很多不同,因为它们的 b+ 树算法不同。

I have found some different b+ tree insertion algorithms from internet.我从互联网上找到了一些不同的 b+ 树插入算法。 shown in below.如下图所示。

Algorithm 1算法 1

https://imgur.com/a/uTtZBb2 https://imgur.com/a/uTtZBb2

Algorithm 2算法2

https://imgur.com/a/eMpvON5 https://imgur.com/a/eMpvON5

Algorithm 3算法3

https://imgur.com/a/YznNLwm https://imgur.com/a/YznNLwm

Algorithm 4算法 4

https://imgur.com/a/dxk6H27 https://imgur.com/a/dxk6H27

I have tried 2 questions get from library.我已经尝试了从图书馆获取的 2 个问题。 There is 2 possible answers, its confused my mind.有2个可能的答案,这让我很困惑。

https://imgur.com/a/yXW0gYQ https://imgur.com/a/yXW0gYQ

Is there any exact answer or there are several possible answers are allowed for b+ tree?是否有任何确切的答案或 b+ 树允许有几种可能的答案?

*Sorry i cannot insert image due to not enough reputation. *抱歉,由于声誉不够,我无法插入图片。

I suggest you to look the first image and the last one they are easier to understand the algorithm due to diagram examples.我建议您查看第一张图片和最后一张图片,由于图表示例,它们更容易理解算法。 There are not multiple answers all images show the same algorithm but they maybe use different notations.没有多个答案,所有图像都显示相同的算法,但它们可能使用不同的符号。 The Basic idea of the B+ tree is simple. B+树的基本思想很简单。

First L+1 keys insertion till root node is created:首先插入 L+1 个密钥,直到创建根节点:

1.|Starting on how many keys do you want your Node to have? 1.|从您希望您的节点拥有多少个密钥开始? Let's assume L is the length of node (aka the number of keys in the node) eg L=4.让我们假设 L 是节点的长度(也就是节点中的键数),例如 L=4。 You starting inserting keys into the node, and each time you insert a new key in the node you sort them (sort every time you inserting a new key, except the first time).您开始将键插入节点,并且每次在节点中插入新键时都会对它们进行排序(每次插入新键时都进行排序,第一次除外)。

2.| 2.| then you have an if statement checking if a node is full aka 4 keys in the node( use a counter and increase it per insertion then compare it with L).然后你有一个 if 语句检查节点是否已满,也就是节点中的 4 个键(使用计数器并在每次插入时增加它,然后将它与 L 进行比较)。

3.|If a node is full split in half, create a temporary node in which you will add the middle key and create two new nodes connected to each other and also connected to the first. 3.|如果一个节点完全分裂成两半,创建一个临时节点,你将在其中添加中间键并创建两个相互连接并也连接到第一个的新节点。

After L+1 keys have inserted:插入 L+1 键后:

You build your tree bottom-up.您自下而上构建树。 Starting from leaf nodes从叶子节点开始

After the first split you will need to search in the tree for the right place to insert a new key since you need it to be shorted, check if the node where your key will be inserted if is full before insertion and after and if it is split it.第一次拆分后,您需要在树中搜索正确的位置以插入新密钥,因为您需要将其短路,检查插入密钥的节点是否在插入前和插入后已满以及是否已满拆分它。 But this time when you split a node you insert your middle key to the parent node and then check if the parent is full or not.但是这次当你拆分一个节点时,你将中间键插入父节点,然后检查父节点是否已满。

Basic functionality you will need to do insertion in a B+ tree is a) search_method() , b)a short_method() and then c)insertion() see also for linked list how it works在 B+ 树中插入所需的基本功能是a) search_method() , b) a short_method()然后c)insertion()另请参阅链表如何工作

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

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