×

B+ Tree in Data Structure

A B-Tree extension called B+ Tree, which enables effective search, insertion, and deletion operations.

Both Records and keys can be stored in internal and leaf nodes in a B tree. Contrarily, records (data) can only be kept on leaf nodes in a B+ tree, while inside nodes can only hold key values.

To improve the effectiveness of search queries, the leaf nodes of a B+ tree are linked together as singly linked lists.

The enormous amount of data that cannot be kept in the main memory is saved in B+ Trees. The internal nodes (keys to access records) of the B+ tree are saved in the main memory, while leaf nodes are kept in the secondary memory due to the constant size restriction of the main memory.

B+ Tree in Data Structure

B-tree and B+ trees are typically used to achieve dynamic multilevel indexing. However, the disadvantage of the B-tree used for indexing is that it also keeps the data pointer (a pointer to the disc file block containing the key value), corresponding to a certain key value, in the B-tree node. This method significantly decreases the number of items that can fit inside a B-tree node, which leads to an increase in the B-level tree's structure and longer search times for records. By only storing data pointers at the tree's leaf nodes, the B+ tree gets rid of the aforementioned flaw. As a result, the interior nodes of the B tree and the leaf nodes of a B+ tree have very distinct structures. It should be emphasized that since data pointers are only present at leaf nodes, all key values and their accompanying data pointers to the disc file block must be stored by leaf nodes in order for them to be accessible. Additionally, the leaf nodes are connected to offer organized access to the records. Therefore, the leaf nodes constitute the index's first level, with the internal nodes being the other levels in a multilevel index. To only serve as a conduit for controlling the leaf nodes' key values, some of them also appear in the internal nodes.

It just acts as a medium to control the search for recordings. From the above discussion, unlike B-trees, B+-trees have two orderings, 'a' and 'b', one for internal nodes and one for external (leaf) nodes.

The structure of the internal nodes of a B+ tree of order 'a'

B+ Tree in Data Structure


Each internal node has the format:

  • where c <= a, each Pi is a tree pointer (i.e. points to another node in the tree) and each Ki is a key value.
  • Each internal node has:
    K1< K2< …. < Kc-1
  • For each search field value 'X' in the subtree pointed to or by Pi, the following conditions hold:
    if Ki-1 < X <= Ki, 1 < i < c and Ki-1 <; X, i = c
  • Each interior node has at most "a" tree pointers.
  • The root node has at least two tree pointers, and the other internal nodes each have at least \ceil(a/2) tree pointers.
  • If an interior node has a 'c' pointer (c <= a), it has a 'c - 1' key value.

Advantages of B+ Trees

  • Recordings can be recalled with the same number of disk accesses.
  • The height of the tree remains balanced and is lower compared to the B tree.
  • Data stored in a B+ tree can be accessed sequentially and directly.
  • Keys are used for indexing.
  • Searches are faster because data is stored only in leaf nodes.

Negative aspects of B+ Tree:

The difficulty of accessing the keys in a sequential manner is the main disadvantage of B-tree. Rapid sequential access is also possible while maintaining rapid random access in the B+ tree.

Application of a B+ tree:

  • Indexing at multiple levels
  • Faster tree operations (insert, delete, search)
  • Database indexing

Insertion into the B+ Tree

Step 1:
Paste the new node as a leaf node

Step 2:
If the leaf does not have the required space, split the node and copy the intermediate node to the next index node.

Step 3:
If the index node does not have the required space, split the node and copy the intermediate elements to the next index page.

Deletion in B+ Tree

Step 1:
Clear keys and data from the sheet.

Step 2:
If the leaf node contains fewer than the minimum number of elements, merge the node with its siblings and remove the key between them.

Step 3:
If the index node contains fewer than the minimum number of elements, merge the node with its siblings and move the key down between them.


Related Topics

Minimum Spanning Tree

Before getting to know about the minimum spanning tree, we should first discuss about what is a spanning tree. A spanning tree is basically a sub or minimized graph that...

7 minutes read.

Right side view of binary tree

The right view of the binary tree is generally known to be that side viewed from the right direction of the point of view. To be more precise, the right-side...

8 minutes read.

Delete N nodes after M nodes of a linked list

Delete N nodes after M nodes of a linked list In this problem, we have given a linked list and two integers M and N. We need to traverse the linked...

3 minutes read.

Implementation of Queue

Implementation of queue: We can implement the queue through the array and linked list. An array is the easiest way to implement the queue. When a queue is created with the...

7 minutes read.

B Tree vs B + Tree: Data Structure

Difference Between B Tree and B+ Tree What is B Tree? B-Tree is a self-balancing or special type of m-way tree. B-Trees are used mainly in disc access. If we want...

3 minutes read.

Find Bridges in a Graph

You have been given a graph. You have to find out the bridges in that graph. Graph may be connected or disconnected. You have to print vertices of particular edge...

4 minutes read.

Asymptotic Notation

Asymptotic notation is expressions that are used to represent the complexity of algorithms. The complexity of the algorithm is analyzed from two perspectives:  Time complexitySpace complexity Time complexity The time complexity of an algorithm is the...

3 minutes read.

Counts the number of times a given element occurs in a Linked List

Counts the number of times a given element occurs in a Linked List This article will explain how we can count the occurrences of a particular element in a list. Here,...

3 minutes read.

Deletion in Binary Search Tree

Implementation #include <iostream> using namespace std; struct _nod {   int ky;   struct _nod *Lft, *Rt; }; // Creating a node in the binary tree. struct _nod *nw_nod(int Itm) {   struct _nod *temp = (struct _nod *)malloc(sizeof(struct...

4 minutes read.

Pairwise swap elements of a given linked list

Pairwise swap elements of a given linked list In this problem, we have given a linked list, and we need to pairwise swap elements of the given linked list. Example:                                     Input:1 ->3...

4 minutes read.

Bubble Sort vs Selection Sort

In this article, we will discuss the basic differences between these two sorting algorithms. Let us have a quick overview of what these sorting algorithms are? And what are the...

6 minutes read.

Diameter of a Binary Tree

Implementation We will now witness the implementation of the diameter of a binary tree. // Creating a recursive and challenging C program that will help us determine the diameter of a binary...

4 minutes read.

Equal Sum

Find an element in array such that the sum of left array is equal to the sum of right array You have been given an array of numbers. You have to...

4 minutes read.

Fundamental of Algorithms

An algorithm is a part of any programming solution or coding. If we have to make a solution then first we have to think of a clear idea about the...

13 minutes read.

Function to Create a Copy of Binary Search Tree

Implementation // creating a new hashmap in the language C++ that will help us clone a binary tree with arbitrary pointers.  #include<iostream> #include<unordered_map> using namespace std; /* A given binary tree has a record, a...

9 minutes read.

Finding Rank in a Binary Search Tree

Implementation // writing a C++ program to find out the rank and element in the program.  #include <bits/stdc++.h> using namespace std; struct __nod { int record; __nod *Lft, *Rt; int LftSize; }; __nod* new__nod(int record) { __nod *temp = new __nod; temp->record...

6 minutes read.

Asynchronous advantage actor-critic (A3C) Algorithm

The Asynchronous advantage actor-critic (A3C) Algorithm is one of the latest algorithms developed by the Artificial Intelligence division, Deep Mind at Google. It is used for the Deep Reinforcement Learning...

3 minutes read.

Find all possible words from board

We have been given a dictionary of words and a board of characters from which we can form strings. Now, we have to check if the string is present in...

5 minutes read.

Time Complexity of Selection Sort in Data Structure

What is Time Complexity? The term “Time complexity” can be defined as the number of times executions made of a particular sequence of instructions and not the total amount of time...

3 minutes read.

Applications of trees in data structures

Data structures Storage used to organize and store data is known as the data structure. It is a method of managing computerized data to translate or retrieve it more efficiently. A...

7 minutes read.