Search code examples
algorithmdata-structuresb-tree

Which item goes up while inserting in a full node in a B-tree of order 5 and why?


I'm trying to learn designing a btree.
Here are the values to develop a btree of order 5.

1,12,8,2,25,6,14,28,17,7,52,16,48,68,3,26,29,53,55,45,67.

When I insert 25, it breaks into child nodes

         8
      /     \
    1 2    12 25

may I I know on what basis 8 comes up as parent ? Why not any other number ? What if the order of btree would be 4 ?


Solution

  • In a B-tree of order 5 each node (except the root) must have 2 to 4 values in it.

    At the point you enter 25, the node has the values 1,2,8,12. In order to have at least 2 values in each new child (1,2) and (12,25) you have to split at 8.