- 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

# B+ tree Insertion in Data Structure

Here we will see, how to perform the insertion into a B+ Tree. Suppose we have a B+ Tree like below −

**Example of B+ Tree** −

To insert an element, the idea is very similar to the B-Tree, if one element is inserted, that will be stored at the leaf node. If that is present in some internal node, then it will also be there, at the leaf as right child of itself.

Suppose we want to insert 65 into the tree. So that is greater than 60, and less than 75. Then it will be inserted into the middle sub-tree. Now, 65, will be inserted into node after 63, then that node will be divided into two parts, 65 will go up, and 65 will also be there at the right node of it.

B+ Tree after inserting 65.

## Algorithm

**BPlusTreeInsert(root, key)** −

**Input** − The root of the tree, and key to insert

We will assume, that the key is not present into the list Start from root node, perform exact match for key as ‘key’ till a leaf node. Let the search path be x_{1}, x_{2}, … , x_{h}. The x_{1}is first node so root, then x_{h}is leaf node. Each node x_{i}is parent of x_{i+1}Insert the new object where key is ‘key’, and value is v into x_{h}. i := h while x_{i}overflows, do divide x_{i}into two nodes, by moving the larger half of the keys into a new node p. if x_{i}is leaf node, link p into the linked list among leaf nodes. identify a key k, to be inserted into the parent level along with child pointer pointing p. The choice of k depends on the type of the node x_{i}. If x_{i}is leaf node, we will perform copy up. So smallest key in p, is copied as k to the parent level. On the other hand, if x_{i}is non-leaf node, then we will perform push up. So smallest key in p, will be copied into k, in the parent node. if i = 0, then create a new index node as the new root. In the new root store node with key k, and two child x_{i}and p. return else insert a key k and a child pointer pointing to p, into node x_{i-1}. i := i – 1 end if done

- Related Questions & Answers
- B-tree Insertion in Data Structure
- The B-tree in Data Structure
- B-tree Deletion in Data Structure
- B-tree Query in Data Structure
- B+ tree Query in Data Structure
- The B+ tree in Data Structure
- B+ tree Deletion in Data Structure
- Insertion in the Red Black Tree in Data Structure
- Tree Data Structure in Javascript
- R* Tree in Data Structure
- Hilbert Tree in Data Structure
- Insertion into a Max Heap in Data Structure
- Insertion Into a Max HBLT in Data Structure
- Binary Tree ADT in Data Structure
- Unrooted binary tree in Data Structure