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


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

Subject: Data Structures

Step 1: Initialize the B-Tree

  • Create a new root node with order 5.
  • Insert the first data item (10) into the root node.

Step 2: Insert 20

  • Since the root node is not full, insert 20 into the root node.
  • The root node now contains the following data items: 10, 20.

Step 3: Insert 30

  • Since the root node is not full, insert 30 into the root node.
  • The root node now contains the following data items: 10, 20, 30.

Step 4: Insert 40

  • Since the root node is full, we need to split it.
  • Create a new node and insert 20 and 30 into it.
  • Make the new node the left child of the root node.
  • Create a new node and insert 40 into it.
  • Make the new node the right child of the root node.
  • The root node now contains the following data items: 10.

Step 5: Insert 10 (Duplicate)

  • Since the left child of the root node (the node containing 20 and 30) is not full, insert 10 into it.
  • The left child of the root node now contains the following data items: 10, 20, 30.

Step 6: Insert 50

  • Since the right child of the root node (the node containing 40) is not full, insert 50 into it.
  • The right child of the root node now contains the following data items: 40, 50.

Step 7: Insert 60

  • Since the right child of the root node is full, we need to split it.
  • Create a new node and insert 40 and 50 into it.
  • Make the new node the left child of the right child of the root node.
  • Create a new node and insert 60 into it.
  • Make the new node the right child of the right child of the root node.
  • The right child of the root node now contains the following data item: 40.

Step 8: Insert 55

  • Since the left child of the right child of the root node (the node containing 40 and 50) is not full, insert 55 into it.
  • The left child of the right child of the root node now contains the following data items: 40, 50, 55.

Step 9: Insert 65

  • Since the right child of the right child of the root node (the node containing 60) is not full, insert 65 into it.
  • The right child of the right child of the root node now contains the following data items: 60, 65.

Final B-Tree

The final B-Tree is as follows:

10 / \ 20 40 / \ / \ 10 30 50 60 \ 55 65

Properties of the B-Tree

  • The B-Tree is of order 5.
  • The root node has 1 data item and 2 children.
  • The internal nodes have between 2 and 5 data items and between 3 and 6 children.
  • The leaf nodes have between 1 and 5 data items.