Introduction to the B-Tree Insertion Process

Introduction to the B-Tree Insertion Process

In the previous article https://www.jb51.net/article/154153.htm we introduced the properties of B-tree. In this article we will introduce the insertion process of B-tree.

The insertion process and the tree construction process are essentially the same, that is, both perform insertion operations and adjust the B-tree after insertion.

We set the order of the B-tree to 5. Construct a B-tree using the key sequence {1,2,6,7,11,4,8,13,10,5,17,9,16,20,3,12,14,18,19,15}.

Because the order of the tree is 5, each node has at most 5 child nodes, and the number of keywords in each node is 3 to 4.

So, the first step is to insert 1, 2, 6, 7 as a node.

Then insert 11 and get 1, 2, 6, 7, 11. Because the number of nodes exceeds 4, the node needs to be split. Select the middle node 6 and promote it to the parent node, so we get:

There is a rule that newly inserted nodes always appear on leaf nodes. Then insert 4, 8, and 13 directly, and you get

Then insert 10. We get

Because there are 5 elements in the lower right node, which exceeds the maximum number of 4, it needs to be split and the middle node 10 is promoted to be together with 6 to form the following structure.

Then insert 5, 17, 9, 16, and get the following

Then insert 20. After inserting 20, the number of elements in the lower right node is 5, which exceeds the maximum number of 4. Therefore, 16 needs to be increased to form the following structure

Then insert 3, 12, 14, 18, and 19 to form the following structure.

Then inserting 15 will cause 13 to be promoted to the root node. At this time, the root node will have 5 nodes. Then, 10 in the root node will be promoted again, forming the following structure.

Finish.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Introduction to the properties of B-Tree
  • Differences between MySQL Hash index and B-Tree index
  • Analysis of B-Tree Implementation Details in SQLite
  • How to choose between bitmap index and B-tree index in use
  • Based on the use of B-tree and B+ tree: a detailed introduction to data search and database indexing
  • A brief discussion on MySQL B-tree index and index optimization summary
  • Complete B-tree algorithm Java implementation code
  • In-depth understanding of C language B-tree
  • Introduction to the deletion process of B-tree

<<:  How to implement online hot migration of KVM virtual machines (picture and text)

>>:  Introduction to the deletion process of B-tree

Recommend

Detailed explanation of Object.create instance usage in js

1. Create a new object using the Object.create() ...

MySQL master-slave replication principle and practice detailed explanation

Table of contents Introduction effect principle f...

How to get the contents of .txt file through FileReader in JS

Table of contents JS obtains the .txt file conten...

Raspberry Pi msmtp and mutt installation and configuration tutorial

1. Install mutt sudo apt-get install mutt 2. Inst...

Briefly describe the difference between Redis and MySQL

We know that MySQL is a persistent storage, store...

What to do if the online MySQL auto-increment ID is exhausted

Table of contents Table definition auto-increment...

Use of Linux usermod command

1. Command Introduction The usermod (user modify)...

Implementation of Nginx configuration of multi-port and multi-domain name access

To deploy multiple sites on a server, you need to...

Introduction to TypeScript basic types

Table of contents 1. Basic types 2. Object Type 2...

Summary of Linux Logical Volume Management (LVM) usage

Managing disk space is an important daily task fo...

MySQL database Load Data multiple uses

Table of contents Multiple uses of MySQL Load Dat...

MySQL slow query pitfalls

Table of contents 1. Slow query configuration 1-1...