×

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

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.

Why is Binary Heap Preferred over BST for Priority Queue

A priority queue is a linear and ordered collection of elements in which each element has an attribute named priority and the priority attribute decides the order in which elements...

2 minutes read.

Binary Search

Binary Search: When there is a large data structure, the linear search takes a lot of time to search the element. The binary search was developed to overcome the lack...

7 minutes read.

Operations on 1D-Arrays

One Dimensional Array Operations Basic Methods The fundamental operations enabled by an array are listed below. Traverse prints each element of the array one by one.Insert a new element at the specified index.Delete...

8 minutes read.

Linear Search

Searching: In the data structure, searching is the process in which an element is searched in a list that satisfies one or more than one condition. Types of searching There are two...

4 minutes read.

What is a full Binary Tree?

A full binary tree is considered to be a special kind of binary tree in which every single node or leaf node present either contains two children or no children...

4 minutes read.

Queue operations in Data Structure

Queue - Queue is a linear data structure or first in first out data structure means the first element added in the queue will be removed first and the last...

7 minutes read.

Selection Sort

In each iteration of the selection sort algorithm, the smallest item from an unsorted list is chosen and placed at the top of the unsorted list. Algorithm of Selection Sorting In order...

3 minutes read.

What Should We Learn First? Trees or Graphs in Data Structures

A data structure is a database used to store and manage data and optimize and manage computing resources. A data structure is a form used intelligently and quickly to store,...

6 minutes read.

Function to Insert a Node in a Binary Search Tree

Implementation // writing C++ code that will help us in implementing the insertion operation in a binary search tree. #include <bits/stdc++.h> using namespace std; // creating a new binary search tree node struct __nod { int...

8 minutes read.

Program to calculate the area of the circumcircle of an equilateral triangle

You have given one value which represents the side of the equilateral triangle. You have to find out the area of the circumcircle. Let’s take an example - For the above...

3 minutes read.

Stack Using Linked List

In the linked list implementation of the stack, we use a linked list as the primitive data structure to create the stack. It is called the dynamic implementation of the...

6 minutes read.

Assembly Line Scheduling

If we take an example of a car factory, there are two assembly lines. In an assembly line, we can assemble and repair the parts of a car. Now, suppose...

5 minutes read.

Collision Resolution Techniques

Collision Resolution Techniques Collision in hashing In this, the hash function is used to compute the index of the array.The hash value is used to store the key in the hash table,...

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

Queue Implementation using stacks Data Structure

Queue Implementation using stacks In this problem, we have stack data structure which supports only push() and pop() operations. We are required to implement a queue data structure using the instances...

4 minutes read.

Given a Binary Tree, Check if it's balanced

Implementation /*Creating a C++ program that will help us identify whether the given tree is height-balanced or not.  */ #include <bits/stdc++.h> using namespace std; /* A particular binary tree node consists of data with some...

4 minutes read.

String Operations in Data Structures

Operations on Strings Reversing the order of words in a sentence Reversing a string is a technique that reverses or alters the order of a given string so that the last character...

9 minutes read.

Find out the area between two concentric circles

You have given two values of the radius of two circles. You have to find out the area between these two circles. Let's take an example - For the above diagram,...

3 minutes read.

Array vs Linked List: Data Structure

Data structure: Difference Between Array and Linked List What is Array? An array is a linear data structure that can store similar data items for further processing. The similar data items...

3 minutes read.