B-Tree and its creation process demonstration

Brief description of B-Tree

A Balanced Tree Of Order m (Balanced Tree Of Order m) is a balanced m-way search tree

As shown in the figure is a B number with an order of 5. A node can store 4 keywords, and a node has at most 5 references. 0012, 0030, and 0051.0075 are the 4 keywords of the root node and contain 5 Address reference

B-Tree properties

  • The leaf nodes have the same depth, and the pointer of the leaf node is empty
  • The data in the node increases from left to right
  • When B-Tree is used as an index element, all index elements cannot be repeated

B-tree creation process

First define a 5th order B tree (balanced 5-way search tree), now we need to put 4, 9, 32, 12, 24, 30, 51, 29, 69, 31, 90, 70, 75, 79,, 80 , 85, 91, these numbers construct a 5-level tree;

1. Insert 4.9.32.12

2. Insert 24

3. Insert 30

4. Insert 51

5. Insert 29

6. Insert 69, 31

7. Insert 90

8. Insert 70, 75, 79

9. Insert 80, 85, 91

Summarize the rule: When inserting an element, because B-Tree is also a type of search tree, that is, the left element is larger than the right element. Take the 5th order B-Tree as an example. When the number of elements is less than 4, follow the order from left to right. Sort by size in turn. When the element of the inserted current node is greater than the order of the B-Tree, in this example, when the element=0, a new node is created and the element is placed, and the inserted element ends; when the element< 4 and> 0, just insert the elements directly in order, the end of the inserted element, when the element = 4, put the inserted elements into the node in order, and then select a number as the parent node of the current node ( The rule for node selection is (n+1)/2 rounded off), in this case (5+1)/2=3, that is, the third element is selected and placed in the parent node. If there is no parent node, it is created If there is a parent node, the insertion ends; if the parent node element is less than 4, just insert the elements in order, and the insertion ends; and if the parent node element=4, then repeat the above fission operation until the end of the insertion .

Data structure dynamic demonstration website, link developed by foreign universities: https://www.cs.usfca.edu/~galles/visualization/Algorithms.html

Guess you like

Origin blog.csdn.net/a1_HelloWord/article/details/104307914