Contents

B-Trees

i. Properties of B-Trees

B-trees address effectively all of the major problems encountered when implementing disk-based search trees:

A B-tree of order mm is defined to have the following shape properties:

Figure [11.6.1] shows a B-tree of order four. Each node contains up to three keys, and internal nodes have up to four children.

Btree Example

Figure [11.6.1]: A B-tree of order four.

ii. B-Trees insertion

B-tree insertion is a generalization of 2-3 tree insertion.

  1. The first step is to find the leaf node that should contain the key to be inserted,space permitting.

  2. If there is room in this node, then insert the key.

  3. If there is not, then split the node into two and promote the middle key to the parent.

  4. If the parent becomes full, then it is split in turn, and its middle key promoted.

Further more:
Note that this insertion process is guaranteed to keep all nodes at least half full. For example, when we attempt to insert into a full internal node of a B-tree of order four, there will now be five children that must be dealt with. The node is split into two nodes containing two keys each, thus retaining the B-tree property. The middle of the five children is promoted to its parent.

B+ Trees

i. Difference between B+ Trees and B-Trees / BST

The B+ tree is essentially a mechanism for managing a sorted array-based list, where the list is broken into chunks.

The most significant difference between the B+ tree and the BST (Binary Search Tree) or the standard B-tree is that :

Java-like pseudocode representation for the B+ Tree node interface

/** Interface for B+ Tree nodes */
public interface BPNode<Key,E> {
      public boolean isLeaf();
      public int numrecs();
      public Key[] keys();
}

ii. B+ Tree insertion

B+ tree insertion is similar to B-tree insertion.

  1. First, the leaf L that should contain the record is found.

  2. If L is not full, then the new record is added, and no other B+ tree nodes are affected.

  3. If L is already full, split it in two (dividing the records evenly among the two nodes) and promote a copy of the least-valued key in the newly formed right node. As with the 2-3 tree, promotion might cause the parent to split in turn, perhaps eventually leading to splitting the root and causing the B+B+ tree to gain a new level.

B+ tree insertion keeps all leaf nodes at equal depth.

ii. B+ Tree deletion

To delete record R from the B+ tree:

  1. first locate the leaf L that contains R.

  2. If L is more than half full, then we need only remove R, leaving L still at least half full.

  3. If deleting a record reduces the number of records in the node below the minimum threshold (called an underflow), then we must do something to keep the node sufficiently full.
    3.1 The first choice is to look at the node's adjacent siblings to determine if they have a spare record that can be used to fill the gap.

If so, then enough records are transferred from the sibling so that both nodes have about the same number of records. This is done so as to delay as long as possible the next time when a delete causes this node to underflow again. This process might require that the parent node has its placeholder key value revised to reflect the true first key value in each node.

  1. If neither sibling can lend a record to the under-full node (call it N), then N must give its records to a sibling and be removed from the tree. There is certainly room to do this, because the sibling is at most half full (remember that it had no records to contribute to the current node), and N has become less than half full because it is under-flowing. This merge process combines two subtrees of the parent, which might cause it to underflow in turn. If the last two children of the root merge together, then the tree loses a level.

B* Trees (B+ Tree Variant)

The B* tree is identical to the B+ tree, except for the rules used to split and merge nodes.

Analysis

Typical database applications use extremely high branching factors, perhaps 100 or more. Thus, in practice the B-tree and its variants are extremely shallow.

i. Examle, B(*) Tree 's order = 100 (Threshold)

IMPORTANT: Insertion and deletion guarante to keep all nodes at least half full.

1. height one
2. height two
3. height three
4. height four

Reference