×

B-Tree Insertion in DBMS

A B-tree is a special type of m-way tree, commonly used for disk access. A B-tree of order m can have at most m-1 keys and m descendants. B-trees are advantageous because they allow nodes to hold many keys and key values while keeping the height of the tree relatively small.
All properties of an m-way tree exist in a B-tree of order m. Additionally, it has the following properties:

  • No node in the B-tree has more than m children.
  • All B-tree nodes, except roots and leaves, have at least m/2 descendants.
  • A base node must have at least two elements.
  • Each leaf node must be at the same level.
  • Not all nodes need to have the same number of children, but each node should have half that number.
  • Inserting an element into a B-tree requires two steps:
    Find a suitable node to place the element and split if necessary. This insertion method always follows a bottom-up approach.
    New keys are always placed on the outermost node. Use k as the key to insert. We follow a similar approach to binary search trees, starting at the root node and moving down until we reach a leaf node. When a leaf node is reached, the key is inserted into that leaf node.
  • Unlike BST, the number of keys a node can hold is limited and predetermined. Before we put the key inside the node, make sure the node has extra capacity.

Inserting Data into B-Tree

Insertion of a new item into a B-Tree is done with the insertion method. The simplest form of this method is to make a copy of the node that you want to insert into and then insert it into the place where the original node was.

If the tree does not contain any nodes, create a root node and place the key within it. Increase the maximum number of keys that can be stored in the node.
Look for the right node to insert.

Once the node reaches capacity, proceed with the steps below.

  • Arrange items from smallest to largest.
  • Now there are elements that go beyond that limit. halfway share
    Drag the middle key to the top left so that the two adjacent keys become its child nodes.
    • If the node is not filled, follow the steps below:
      Arrange the nodes in ascending order.

While using a proactive insertion algorithm, when a node is full, it splits it before descending to it. The advantage of pre-split is that you don't have to traverse the same node twice. If we don't split the nodes before accessing them, but only decompose them when new keys are added (proactive approach), we might re-traverse each node from leaf to root. This happens in situations where all nodes on the root are completely filled from root to end. When you reach the end of a branch of the tree, split it and raise the key. When the button moves up, it splits the parent node (because it is already full). This domino effect does not occur with this pre-insertion process. However, this aggressive insertion has its drawbacks. You might end up creating splits that you don't want.

Use of Insertion

An example of insertion is the addition of an element to a B-Tree. A new key is created, and then inserted into the B-Tree. This new key can then be used when searching for data in the tree.

A common use for insertion is when a user wants to add a new column to a table. For example, if there is already a column named "Phone" but users want to add another column called "Mobile". Adding two columns adds more data, which means more space within the table and thus more space required in the database. In this case, new rows are added to the end of each table row. The key value pair is used as the index for both columns when looking up values in either column (just as it would be if both columns were added at once).

It can be done in two ways:

1)  You can use the copy() method on your tree, which will make a copy of the item at the top level (i.e., your root node). Then, you can insert it at any location in your tree by calling insert() on this new copy.

2)  You can create an array with several items and then use push_back() or insert() on each array element to add them as children of their respective parent nodes.

Algorithm

STEP:1- Find the leaf node to which X should be added using the SEARCH method for M-way trees (explained above).

STEP 2- Add X to this node where it belongs among the existing values. Because it is a leaf node, subtrees are not an issue.

STEP 3- After adding X, if the node contains M-1 or less values, we are done.

STEP 4- We refer to a node as having overflowed if there are M nodes after adding X. We divided the node into three sections to fix it as follows:

  • Left: the initial values for (M-1)/2
  • The middle value is position 1 plus ((M-1)/2)
  • the most recent (M-1)/2 values

Related Topics

Redundancy in DBMS

Data redundancy is a situation that is created in the database in which the same amount of data is stored in two different places. The different places are found in a...

3 minutes read.

Functional Dependencies

Functional Dependencies (FD) in the relational database management system occurs when one attribute in a relation uniquely determines other attribute in that relation. It describes the relation between the attributes. The term functional...

2 minutes read.

Checkpoint in DBMS

A checkpoint in DBMS is used to define a point of the transaction that is in a consistent state and then all the transactions will be in the committed state...

4 minutes read.

Integrity Constraints in DBMS

Integrity constraints in DBMS (Database Management System) are used to ensure the accuracy and consistency of data in a database. They are a set of rules that define the allowed...

1 minute read.

Domain Constraints in DBMS

Introduction about DBMS:- DBMS stands for DataBase Management System. DBMS(DataBase Management System) is a type of software by which we can save and retrieve the user's data with the security process....

3 minutes read.

Types of DBMS

Database Management System A software that is programmed to enable the user to create and maintain a database. Using DBMS, we can implement create, read, update and delete operations on the...

4 minutes read.

Concurrent Execution of Transaction

In the transaction process, a system usually allows executing more than one transaction simultaneously. This process is called a concurrent execution. Advantages of concurrent execution of a transaction Decrease waiting time or...

4 minutes read.

Characteristics of DBMS

Introduction to DBMS: A database management system (DBMS) is a software application that is designed to manage and organize data stored in a database. It is responsible for storing, retrieving, and...

3 minutes read.

Components of Relational Database Management System

A relational database management system compromises various component. Tables, records, attributes, instances, schemas and keys together form a relational database. In this page, we will discuss each component of RDBMS in...

4 minutes read.

Specialization in DBMS

Specialization in DBMS In the database management system, specialization breaks the higher-level entity into two or more than two lower entities. The main motive of this concept is to share the...

2 minutes read.

Query processing in DBMS

Operations on DBMSs are made much simpler, more organized, and methodical with SQL. These are not only simpler for people to comprehend, but after gaining a basic comprehension of them, they...

4 minutes read.

Redundancy in Database Management System

Redundancy in a database management system (DBMS) refers to the duplication of data within the database. This duplication can occur in multiple ways, such as having multiple copies of the...

13 minutes read.

B-Tree Insertion in DBMS

A B-tree is a special type of m-way tree, commonly used for disk access. A B-tree of order m can have at most m-1 keys and m descendants. B-trees are...

4 minutes read.

Relational Algebra in DBMS

Relational Algebra is a widely used procedural query language, which takes instances of one or more relation as an input and generates a new relation as an output. It uses a different...

6 minutes read.

ER Diagram for Company Database in DBMS

What is ER Diagram? An ER diagram (short for Entity Relationship Diagram), also known as an ERD, is a diagram that shows the relationships of a set of entities stored in...

7 minutes read.

View Serializability in DBMS

View Serializability It is a type of serializability that can be used to check whether the given schedule is view serializable or not. A schedule called as a view serializable if it is view...

4 minutes read.

Meta Data in DBMS

Metadata: Metadata is simply described as information about information. It indicates that the data is described as well as its context. It makes data easier to find, interpret, and organize. I'll...

4 minutes read.

Relational algebra in DBMS

Relational algebra in DBMS Relational algebra is a procedural query language used to retrieve the data from a database in a different way. It works on the relational model. It performs...

3 minutes read.

Levels of Abstraction in DBMS

Data abstraction is a way to hide unwanted or irrelevant information from the end user in DBMS. It helps in enhancing the security of data, and simplifies database design using...

4 minutes read.

Components of DBMS

The database management system (DBMS) represents an essential tool for processing data within effectively structured structures. The database management system consists of important components that work together to maintain the...

6 minutes read.