0

I've just learn B-tree and B+-tree in DBMS. I don't understand why a non-leaf node in tree has between [n/2] and n children, when n is fix for particular tree.

Why is that? and advantage of that?

Thanks !

kju
  • 146
  • 10

2 Answers2

1

This is the feature that makes the B+ and B-tree balanced, and due to it, we can easily compute the complexity of ops on the tree and bound it to O(logn) [where n is the number of elements in the data set].

  • If a node could have more then B sons, we could create a tree with depth 2: a root, and all other nodes will be leaves, from the root. searching for an element will be then O(n), and not the desired O(logn).
  • If a node could have less then B/2 sons, we could create a tree which is actually a linked list [n nodes, each with 1 son], with height n - and a search op will again be O(n) instead of O(logn)

Small currection: every non-leaf node - except the root, has B/2 to B children. the root alone is allowed to have less then B/2 sons.

amit
  • 175,853
  • 27
  • 231
  • 333
0

The basic assumption of this structure is to have a fixed block size, this is why each internal block has n slots for indexing its children.

When there is a need to add a child to a block that is full (has exactly n children), the block is split into two blocks, which then replace the original block in its parent's index. The number of children in each of the two blocks is obviously n div 2 (assuming n is even). This is what the lower limit comes from.

If the parent is full, the operation repeats, potentially up to the root itself.

The split operation and allowing for n/2-filled blocks allows for most of the insertions/deletions to only cause local changes instead of re-balancing huge parts of the tree.

Rafał Dowgird
  • 43,216
  • 11
  • 77
  • 90