B+ Tree

B+ Tree is an extension of B Tree which allows efficient insertion, deletion and search operations.

In B Tree, Keys and records both can be stored in the internal as well as leaf nodes. Whereas, in B+ tree, records (data) can only be stored on the leaf nodes while internal nodes can only store the key values.

The leaf nodes of a B+ tree are linked together in the form of a singly linked lists to make the search queries more efficient.

B+ Tree are used to store the large amount of data which can not be stored in the main memory. Due to the fact that, size of main memory is always limited, the internal nodes (keys to access records) of the B+ tree are stored in the main memory whereas, leaf nodes are stored in the secondary memory.

Advantages of B+ Tree

  1. Records can be fetched in equal number of disk accesses.
  2. Height of the tree remains balanced and less as compare to B tree.
  3. We can access the data stored in a B+ tree sequentially as well as directly.
  4. Keys are used for indexing.
  5. Faster search queries as the data is stored only on the leaf nodes.
  6. Insertion in B+ Tree

    Step 1: Insert the new node as a leaf node

    Step 2: If the leaf doesn't have required space, split the node and copy the middle node to the next index node.

    Step 3: If the index node doesn't have required space, split the node and copy the middle element to the next index page.

Deletion in B+ Tree

        Step 1: Delete the key and data from the leaves.

        Step 2: if the leaf node contains less than minimum number of elements, merge down the node with its sibling and delete              the key in between them.

       Step 3: if the index node contains less than minimum number of elements, merge the node with the sibling and move down         the key in between them.

Posted on by