B-tree and B+-tree definitions

B-tree:

Principle: An m-order B-tree (Balance Tree) has the following characteristics:

  • 1. The root node has at least two children .
  • 2. Each intermediate node contains k-1 elements and k children , where m/2 <= k <= m
  • 3. Each leaf node contains k-1 elements , where m/2 <= k <= m
  • 4. All leaf nodes are located on the same layer .
  • 5. The elements in each node are arranged from small to large, and the k-1 elements in the node are exactly the value domain divisions of the elements contained in k children .

   Advantage:

  • When storing the same number of elements, the height of the tree becomes smaller, which is equivalent to reducing the number of disk IOs and improving performance
  • When the query enters a node with many elements, it only exists in memory for comparison. Compared with the speed of disk IO, the time consumed is negligible [this is why "expansion" is performed on the node]

Disadvantages:

  • Compared with the B+ tree, each node will store data, and the same size disk page will store fewer node elements
  • The query performance is unstable. For example, sometimes the bottom-level leaf nodes may be found, and sometimes the top-level root nodes may be found and returned. The consumption of each query is unstable, and the query time consumption fluctuates greatly.
  • Range query is inconvenient. For example, I want to query all elements that match 6~10 in the figure, and the elements 6~10 are distributed in the tree on both sides from the root node, so the inorder traversal that needs to be passed is very complicated.

Unique features of m-order B+ tree:

  • The middle node with k subtrees contains k elements (k-1 elements in the B tree) , each element does not save data , it is only used for indexing , and all data is saved in the leaf nodes .
  • All leaf nodes contain information of all elements and pointers to records containing these elements , and the leaf nodes themselves are linked in order of key size from small to large.
  • All intermediate node elements also exist in child nodes, which are the largest (or smallest) elements in the child node elements.

Guess you like

Origin blog.csdn.net/yytree123/article/details/125727674