- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# How to create a B-Tree in DBMS?

## Problem

Create a B-Tree of order 4 for the following set of key values −

1,12,8,2,25,6,14,28,17,7,52,16,48,68,3

## Solution

Let us start constructing B-Tree step by step −

**Step 1** − As the given order is 4, the first four items go into root and are arranged in sorted order (ascending).

**Step 2** − Now, we need to insert the fifth element, if we insert the fifth item in root it violates the condition, because the order is 4.

**Step 3** − So, when 25 arrives pick the middle key to make a new root.

**Step 4** − Now 6, 14, 28 are added to the leaf nodes −

**Step 5** − Adding 17 to the right of the leaf node would over fill it, so we take the middle key, promote it to the root and split the leaf.

So split the leaf node and send the 17 to root node,

**Step 6** − 7,52,16,48 get added to the leaf nodes as shown below −

**Step 7** − Adding 68 causes us to split the rightmost leaf, promoting 48 to the root.

**Step 8** − Adding 3 causes us to split the leftmost leaf because it is exceeding the order 4, if we insert 3.

As, 3 becomes the middle element so, promote 3 to the root node by splitting the leftmost leaf.

**Note** − Attempt to insert the new key into a leaf consider two pints, which are as follows −

After inserting if the leaf becomes too big, split the leaf into two and promote the middle key to leaf parent.

Suppose if the parent becomes too big after inserting the key, then split the parent into two, promoting the middle key.

- Related Questions & Answers
- What is B-tree and explain the reasons for using it (DBMS)?
- C++ Program to Implement B Tree
- C++ Program to Implement B+ Tree
- Difference Between B-tree and Binary tree
- The B-tree in Data Structure
- B-tree Query in Data Structure
- B-tree Insertion in Data Structure
- B-tree Deletion in Data Structure
- The B+ tree in Data Structure
- B+ tree Query in Data Structure
- B+ tree Insertion in Data Structure
- B+ tree Deletion in Data Structure
- C++ Program to Perform Sorting Using B-Tree
- What is an expression tree in DBMS?
- How to create a JSON using Jackson Tree Model in Java?