• edited by
10,630 views
14 14 votes

We wish to construct a $B^+$ tree with fan-out (the number of pointers per node) equal to $3$ for the following set of key values:

$80, 50, 10, 70, 30, 100, 90$

Assume that the tree is initially empty and the values are added in the order given.

  1. Show the tree after insertion of $10$, after insertion of $30$, and after insertion of $90$. Intermediate trees need not be shown.
  2. The key values $30$ and $10$ are now deleted from the tree in that order show the tree after each deletion.

3 Answers

Best answer
15 15 votes

$(a) \ B^{+}$ tree insertion: $80,50,10,70,30,100,90$

Order of $B^{+} = p =3$

  • Overflow: When number of key values exceed $p-1=3-1 = 2$

Tree after insertion of  $10:$

Tree after insertion of  $30:$

Tree after insertion of  $90:$

$(b)$

  • Underflow: if leaf node contain $\left \lceil \frac{p}{2}\right \rceil - 1 = 2-1 = 1$ key values.

Deletion of key-value $30:$

Deletion of key-value $10:$

Here when we delete the key-value $10$ then underflow happened, so we can merge this node with the right sibling.

When we merge two nodes then the parent node one value needs to come down i.e. $50$ here.

Now if we try to bring $50$ down then that node will again suffer from underflow as it will become empty.

so we will try to merge this node it with its right sibling i.e. the node which contains $70$

Again, When we merge two nodes(nodes in the 2nd level that contain 50 and 70) then one value of the parent node (i.e. node having $50,70$) needs to come down

So we will bring $70$ down and merge it with $50$ since bringing $70$ down will not cause underflow as $80$ is present in the parent node.

Try it out: https://www.cs.usfca.edu/~galles/visualization/BPlusTree.html

• selected by
18 18 votes

While splitting an internal node we push the middle element to parent and we don’t maintain a copy of that in child internal node.

But while spitting a leaf node we push the middle one to parent and we keep a copy in leaf node as well.

a) 

We don’t keep a copy of 70 in child internal  node when inserting 100

 

b)After deleting 30 and 10 relsuting tree is

 

Play with this tool for better understanding 

https://www.cs.usfca.edu/~galles/visualization/BPlusTree.html

2 2 votes

in the B+ tree order of internal node and order of leaf node are different 

order of internal node is maximum no of children 

order of leaf node is maximum no of key-value pair in the leaf 

in the question, it is given that 

B+ tree with fan-out (the number of pointers per node) equal to 3

so from this, we can easily conclude that the order of the internal node is 3

and order of leaf node is 2   ( just think about it why it is 2 ?? you will get the answer )

for internal node 

since order = 3, so we can have 2 key elements in a node this is  not a problem but when we have 3 key then we have to split them

for leaf node

since order = 2, so we can have 2 key elements in a node with no problem but when we have 3 key then we have to split them

correction in the diagram: every leaf node will point to the next leaf node, by doing this we can observe the fanout of each node is 3

 

 ( now I am giving the answer of question which I had asked earlier  )

Q: why the order of leaf node is 2?

it is because given fan-out (the number of pointers per node) equal to 3 

one pointer point to next leaf and two-pointer point to the record means there are maximum  two record pointer 

and order of leaf node is the maximum number of key-value pair 

so it is 2

• edited by
Position:
Show:

Related questions

13 13 votes
4 answers 4 answers
4.4k
4.4k views
go_editor asked Feb 8, 2018
4,372 views
Consider a relation examinee (regno, name, score), where regno is the primary key to score is a real number.Write an SQL query to list the regno of examinees who have a s...
12 12 votes
3 3 answers
4.4k
4.4k views
go_editor asked Feb 8, 2018
4,436 views
Consider a relation $\text{examinee (regno, name, score)},$ where regno is the primary key to score is a real number.Suppose the relation $\text{appears (regno, centr_cod...
22 22 votes
2 answers 2 answers
7.7k
7.7k views
Kathleen asked Sep 14, 2014
7,693 views
Consider a relation examinee (regno, name, score), where regno is the primary key to score is a real number.Write a relational algebra using $( \Pi, \sigma, \rho, \times)...
80 80 votes
8 answers 8 answers
42.2k
42.2k views
Kathleen asked Sep 14, 2014
42,168 views
Consider Peterson's algorithm for mutual exclusion between two concurrent processes i and j. The program executed by process is shown below.repeat flag[i] = true; turn = ...