简体   繁体   中英

The problem of designing, inserting and deleting of the B+ tree values

I have the question regarding my homework:

1) First of all, assuming that 4 pointers might fit in an internal node and each leaf node can store 4 key values, the B+ tree should be constructed with the following values:

2, 3, 5, 7, 11, 17, 19, 23, 29, 31.

With the site , I've received the tree below. I am not sure if it is right, because the in the leaf nodes, there might have three key values:

在此处输入图像描述

The problem starts with an insertion and deletion. Consequently inserting 9, 10, 8, I've received the tree below:

在此处输入图像描述

But when I delete 23, I describes as below. The problem is, 19 couldn't be alone, since the leaf must be half-full:

在此处输入图像描述

The deleting 19 after that gives the same problem:

在此处输入图像描述

The questions are:

1) is the initial tree is correct?

2) Are my assumptions about deletions are correct?

3) And how must be trees lookalike after the deletion?

With regards.

After deleting 23, you are correct that that leaf node cannot exist if it has less than n/2 keys. There are basically 3 cases for a deletion in B+ Tree:

Case 1: Node still has more than n/2 keys; no changes needed.

If node has less than n/2 keys,

Case 2: Borrow a key from a neighbour leaf node. Update parent nodes.

If none of my neighbours have enough to spare me a key,

Case 3: Merge with a neighbour leaf node. Update parent nodes.

In the case of deleting key 23, the node containing key 19 will look to merge with either of its neighbours. After merging, remember to update your parent nodes!

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