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

When MySQL is upgraded to 5.7, WordPress reports error 1067 when importing data

I recently upgraded MySQL to 5.7, and WordPress r...

How to create scheduled tasks using crond tool in Linux

Preface Crond is a scheduled execution tool under...

Detailed explanation of the execution plan explain command example in MySQL

Preface The explain command is the primary way to...

JavaScript implements mouse control of free moving window

This article shares the specific code of JavaScri...

Summary of several submission methods of HTML forms

The most common, most commonly used and most gener...

How to build a multi-node Elastic stack cluster on RHEL8 /CentOS8

Elastic stack, commonly known as ELK stack, is a ...

Detailed discussion of MySQL stored procedures and stored functions

1 Stored Procedure 1.1 What is a stored procedure...

MySQL query statement simple operation example

This article uses examples to illustrate the simp...

js to achieve a simple lottery function

This article shares the specific code of js to im...

Ubuntu 20.04 Chinese input method installation steps

This article installs Google Input Method. In fac...

Summary of new usage of vi (vim) under Linux

I have used the vi editor for several years, but ...

Let you understand the deep copy of js

Table of contents js deep copy Data storage metho...

Reasons and solutions for MySQL selecting the wrong index

In MySQL, you can specify multiple indexes for a ...