Docsity

B-Trees - Data Base Management System - Lecture Slides, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download B-Trees - Data Base Management System - Lecture Slides and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

B-Trees And B+-Trees

Preview

• B-Tree Indexing

• B-Tree

• B-Tree Characteristics

• B-Tree Example

• B+-Tree

• B+-Tree Characteristics

• B+-Tree Example

What is a B-Tree?

• B-tree is a specialized multiway tree designed

especially for use on disk.

• B-Tree consists of a root node, branch nodes

and leaf nodes containing the indexed field

values in the ending (or leaf) nodes of the

tree.

B-Tree Characteristics

  • In a B-tree each node may contain a large number of keys
  • B-tree is designed to branch out in a large number of directions and to contain a lot of keys in each node so that the height of the tree is relatively small
  • Constraints that tree is always balanced
  • Space wasted by deletion, if any, never becomes excessive
  • Insert and deletions are simple processes
    • Complicated only under special circumstances -Insertion into a node that is already full or a deletion from a node makes it less then half full

B-Tree Insertion

  1. B-tree starts with a single root node (which is also a leaf node) at level
  1. Once the root node is full with p – 1 search key values and when attempt to insert another entry in the tree, the root node splits into two nodes at level 1.
  2. Only the middle value is kept in the root node, and the rest of the values are split evenly between the other two nodes.
  3. When a nonroot node is full and a new entry is inserted into it, that node is split into two nodes at the same level, and the middle entry is moved to the parent node along with two pointers to the new split nodes.
  4. If the parent node is full, it is also split.
  5. Splitting can propagate all the way to the root node, creating a new level if the root is split.

B-Tree Deletion

1) If deletion of a value causes a node to be less than

half full, it is combined with it neighboring nodes,

and this can also propagate all the way to the root.

  • Can reduce the number of tree levels.

*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 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 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.

  • 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 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.