How to create a B-Tree in DBMS?

DBMSDatabaseBig Data Analytics

Problem

Create a B-Tree of order 4 for the following set of key values −

1,12,8,2,25,6,14,28,17,7,52,16,48,68,3

Solution

Let us start constructing B-Tree step by step −

Step 1 − As the given order is 4, the first four items go into root and are arranged in sorted order (ascending).

Step 2 − Now, we need to insert the fifth element, if we insert the fifth item in root it violates the condition, because the order is 4.

Step 3 − So, when 25 arrives pick the middle key to make a new root.

Step 4 − Now 6, 14, 28 are added to the leaf nodes −

Step 5 − Adding 17 to the right of the leaf node would over fill it, so we take the middle key, promote it to the root and split the leaf.

So split the leaf node and send the 17 to root node,

Step 6 − 7,52,16,48 get added to the leaf nodes as shown below −

Step 7 − Adding 68 causes us to split the rightmost leaf, promoting 48 to the root.

Step 8 − Adding 3 causes us to split the leftmost leaf because it is exceeding the order 4, if we insert 3.

As, 3 becomes the middle element so, promote 3 to the root node by splitting the leftmost leaf.

Note − Attempt to insert the new key into a leaf consider two pints, which are as follows −

  • After inserting if the leaf becomes too big, split the leaf into two and promote the middle key to leaf parent.

  • Suppose if the parent becomes too big after inserting the key, then split the parent into two, promoting the middle key.

raja
Published on 08-Jul-2021 08:01:35
Advertisements