B and B+ Tree
B and B+ Tree
B and B+ Tree
Preview
• B-Tree Indexing
• B-Tree
• B-Tree Characteristics
• B-Tree Example
• B+-Tree
• B+-Tree Characteristics
• B+-Tree Example
B-Tree Index
*Shown by analysis and simulation that, after numerous random insertions and
deletions on a B-tree, the nodes are approximately 69 percent full when the
number of values in the tree stabilizes. If this happens , node splitting and
combining will occur only rarely, so insertion and deletion become quite
efficient.
B-tree of Order 5 Example
• All internal nodes have at least ceil(5 / 2) = ceil(2.5) = 3 children (and
hence at least 2 keys), other then the root node.
• The maximum number of children that a node can have is 5 (so that 4 is
the maximum number of keys)
• each leaf node must contain at least 2 keys
B-Tree Order 5 Insertion
• Originally we have an empty B-tree of order 5
• Want to insert C N G A H E K Q M F W L T Z D P R X Y S
• Order 5 means that a node can have a maximum of 5 children
and 4 keys
• All nodes other than the root must have a minimum of 2 keys
• The first 4 letters get inserted into the same node
B-Tree Order 5 Insertion Cont.
• When we try to insert the H, we find no room in this node,
so we split it into 2 nodes, moving the median item G up into
a new root node.
B-Tree Order 5 Insertion Cont.
• Inserting E, K, and Q proceeds without requiring
any splits
B-Tree Order 5 Insertion Cont.
• Inserting M requires a split
B-Tree Order 5 Insertion Cont.
• The letters F, W, L, and T are then added without
needing any split
B-Tree Order 5 Insertion Cont.
• When Z is added, the rightmost leaf must be split. The
median item T is moved up into the parent node
B-Tree Order 5 Insertion Cont.
• The insertion of D causes the leftmost leaf to be split. D happens to be
the median key and so is the one moved up into the parent node.
• The letters P, R, X, and Y are then added without any need of splitting
B-Tree Order 5 Insertion Cont.
• Finally, when S is added, the node with N, P, Q, and R splits, sending
the median Q up to the parent.
• The parent node is full, so it splits, sending the median M up to form a
new root node.
B-Tree Order 5 Deletion
• Initial B-Tree
B-Tree Order 5 Deletion Cont.
• Delete H
• Since H is in a leaf and the leaf has more than the
minimum number of keys, we just remove it.
B-Tree Order 5 Deletion Cont.
• Delete T.
• Since T is not in a leaf, we find its successor (the next item in ascending order),
which happens to be W.
• Move W up to replace the T. That way, what we really have to do is to delete W
from the leaf .
B+- Tree Characteristics