简体   繁体   中英

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.

I have found some different b+ tree insertion algorithms from internet. shown in below.

Algorithm 1

https://imgur.com/a/uTtZBb2

Algorithm 2

https://imgur.com/a/eMpvON5

Algorithm 3

https://imgur.com/a/YznNLwm

Algorithm 4

https://imgur.com/a/dxk6H27

I have tried 2 questions get from library. There is 2 possible answers, its confused my mind.

https://imgur.com/a/yXW0gYQ

Is there any exact answer or there are several possible answers are allowed for b+ tree?

*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.

First L+1 keys insertion till root node is created:

1.|Starting on how many keys do you want your Node to have? Let's assume L is the length of node (aka the number of keys in the node) eg 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.| 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).

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.

After L+1 keys have inserted:

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

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