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

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());

Concurrency Control

What is Concurrency Control? Concurrency Control in Database Management System is a procedure of managing simultaneous operations without conflicting with each other. It ensures that Database transactions are performed concurrently and accurately to produce correct results without violating data integrity of the respective Database. Concurrent access is quite easy if all users are just reading data. There is no way they can interfere with one another. Though for any practical Database, it would have a mix of READ and WRITE operations and hence the concurrency is a challenge. DBMS Concurrency Control is used to address such conflicts, which mostly occur with a multi-user system. Therefore, Concurrency Control is the most important element for proper functioning of a Database Management System where two or more database transactions are executed simultaneously, which require access to the same data. Potential problems of Concurrency Here, are some issues which you will likely to face wh...

Top 10 Most Famous Photographers of All Time

*Top 10 Most Famous Photographers of All Time* If you want to take truly memorable and moving photographs, you can learn something by studying the pictures of famous photographers. Some of the most beloved artists are deceased, but some are still delighting us with their photographs. The list below includes some of the more famous photographers that still impact our lives today. 1. *Ansel Adams* is probably the most easily recognized name of any photographer. His landscapes are stunning; he achieved an unparalleled level of contrast using creative darkroom work. You can improve your own photos by reading Adams’ own thoughts as he grew older, when he wished that he had kept himself strong enough physically to continue his work. 2. *Yousuf Karsh* has taken photographs that tell a story, and that are more easily understood than many others. Each of his portraits tells you all about the subject. He felt as though there was a secret hidden behind each woman and man. Whether he captures a gl...