Create B-Tree of order 5 from the following lists of data items: 20, 30, 10, 10, 50, 40, 50, 60, 55, 65.


Q.) Create B-Tree of order 5 from the following lists of data items: 20, 30, 10, 10, 50, 40, 50, 60, 55, 65.

Subject: Data Structures

To construct a B-Tree of order 5 from the given list of data items, follow these steps:

  1. Initialization:

    • Set the root node to be a leaf node.
    • Insert the first data item (20) into the root node.
  2. Insertion:

    • For each subsequent data item (30, 10, 10, 50, 40, 50, 60, 55, 65):
      • Find the leaf node where the data item should be inserted.
      • If the leaf node has fewer than 5 data items, insert the data item into the leaf node.
      • Otherwise, split the leaf node into two leaf nodes and insert the data item into the appropriate leaf node.
  3. Splitting a Leaf Node:

    • When a leaf node has 5 data items, it must be split into two leaf nodes.
    • To do this, find the middle data item in the leaf node and move it to a new leaf node.
    • Distribute the remaining data items between the two leaf nodes, making sure that each leaf node has between 2 and 5 data items.
  4. Adjusting the Parent Nodes:

    • After splitting a leaf node, the parent node may need to be adjusted.
    • If the parent node has fewer than 5 children, add the new leaf node as a child.
    • Otherwise, split the parent node into two parent nodes and distribute the children between the two parent nodes.
  5. Building the B-Tree:

    • Continue to insert data items into the B-Tree, following the insertion and splitting procedures described above.
    • As the B-Tree grows, it will automatically adjust its structure to maintain the order property.

The resulting B-Tree of order 5 for the given list of data items is shown below:

               (20)
              /   \
            /      \
         (10, 10)   (30, 40)
                     /      \
                 (50)      (55, 60, 65)

This B-Tree satisfies the order property, meaning that each node has between 2 and 5 data items. It also has a balanced structure, with the height of the tree being logarithmic in the number of data items. This makes the B-Tree efficient for searching and retrieval operations.