Skip to main content

B+ Tree

B+ Tree

  • The B+ tree is a balanced binary search tree. It follows a multi-level index format.
  • In the B+ tree, leaf nodes denote actual data pointers. B+ tree ensures that all leaf nodes remain at the same height.
  • In the B+ tree, the leaf nodes are linked using a link list. Therefore, a B+ tree can support random access as well as sequential access.

Structure of B+ Tree
  • In the B+ tree, every leaf node is at an equal distance from the root node. The B+ tree is of the order n where n is fixed for every B+ tree. 
  • It contains an internal node and a leaf node.



Internal node
  • An internal node of the B+ tree can contain at least n/2 record pointers except the root node.
  • At most, an internal node of the tree contains n pointers.

Leaf node
  • The leaf node of the B+ tree can contain at least n/2 record pointers and n/2 key values.
  • At most, a leaf node contains n record pointer and n key values.
  • Every leaf node of the B+ tree contains one block pointer P to point to the next leaf node.

Searching a record in B+ Tree

Suppose we have to search 55 in the below B+ tree structure. First, we will fetch for the intermediary node which will direct to the leaf node that can contain a record for 55.

So, in the intermediary node, we will find a branch between 50 and 75 nodes. Then at the end, we will be redirected to the third leaf node. Here DBMS will perform a sequential search to find 55.


B+ Tree Insertion

Suppose we want to insert a record 60 in the below structure. It will go to the 3rd leaf node after 55. It is a balanced tree, and a leaf node of this tree is already full, so we cannot insert 60 there.

In this case, we have to split the leaf node, so that it can be inserted into the tree without affecting the fill factor, balance, and order.


The 3rd leaf node has the values (50, 55, 60, 65, 70) and its current root node is 50. We will split the leaf node of the tree in the middle so that its balance is not altered. So we can group (50, 55) and (60, 65, 70) into 2 leaf nodes.

If these two have to be leaf nodes, the intermediate node cannot branch from 50. It should have 60 added to it, and then we can have pointers to a new leaf node.

This is how we can insert an entry when there is an overflow. In a normal scenario, it is very easy to find the node where it fits and then place it in that leaf node.


B+ Tree Deletion

Suppose we want to delete 60 from the above example. In this case, we have to remove 60 from the intermediate node as well as from the 4th leaf node too. If we remove it from the intermediate node, then the tree will not satisfy the rule of the B+ tree. So we need to modify it to have a balanced tree.

After deleting node 60 from the above B+ tree and re-arranging the nodes, it will show as follows:


Comments

Popular posts from this blog

Natural Language Processing (NLP)

What is Natural Language Processing (NLP) ? Natural Language Processing (NLP)* is a field of artificial intelligence (AI) that focuses on the interaction between computers and humans using natural language. It involves the development of algorithms and models that enable computers to understand, interpret, and generate human language. Here are key aspects of NLP: 1. *Text Understanding:* NLP systems aim to comprehend the meaning of written or spoken language. This involves tasks such as text classification, sentiment analysis, and named entity recognition. 2. *Speech Recognition:* NLP extends to processing spoken language, converting audio signals into text. This technology is used in voice assistants, transcription services, and more. 3. *Language Generation:* NLP systems can generate human-like text. This is employed in chatbots, language translation services, and content generation. 4. *Machine Translation:* NLP is fundamental to machine translation systems that enable the automatic...

JS Code for Generating OTP

JS Code for Generating OTP -  * Learn how to create a simple JavaScript function to generate a random 4-digit OTP. (GENERATED BY - ChatGPT) function OTP() { let otp = ""; otp = Math.floor(Math.random() * 9000 + 1000); return otp; } console.log("Your OTP is-", OTP());

How To Make Symbols With Keyboard

HOW TO MAKE SYMBOLS WITH A KEYBOARD (Image By - Sharma Guides | Subham232330) Alt + 0153 :   ™  (trademark symbol) Alt + 0169 :   ©  (copyright symbol) Alt + 0174 :   ®  (registered trademark symbol) Alt + 0176 :   °  (degree symbol) Alt + 0177 :  ±  (plus-or-minus sign) Alt + 0182 :   ¶  (paragraph mark) Alt + 0190 :   ¾  (fraction, three-fourths) Alt + 0215 :   × (multiplication sign) Alt + 0162 :   ¢  (thecent sign) Alt + 0161 :   ¡  (upside down exclamation point) Alt + 0191 :   ¿  (upside down question mark) Alt + 1 : ☺ (smiley face) Alt + 2 :   ☻ (black smiley face) Alt + 15 :   ☼  (Sun) Alt + 12 :   ♀  (female sign) Alt + 11 :   ♂  (male sign) Alt + 6 :   ♠  (spade) Alt + 5 :   ♣  (Club) Alt + 3 :   ♥  (Heart) Alt + 4 :   ♦  (Diamond) Alt + 13 :   ♪  (eighth note...