Detailed description of B, B-, B +, and B * trees

Source: Internet
Author: User

Address: http://www.blogjava.net/supercrsky/articles/185167.html

Detailed description of B, B-, B +, and B * trees

BTree

That is, the binary search tree:

1.All non-leaf nodes have at most two sons (LeftAndRight);

2.A keyword is stored on all nodes;

3.The left pointer of a non-leaf node points to the subtree smaller than its keyword, And the right Pointer Points to the subtree larger than its keyword;

For example:

BTree search, starting from the root node. If the query keyword is the same as the node keyword, it hits; otherwise, if the query keyword is smaller than the node keyword, it enters the left son; if it is larger than the node keyword, it enters the right son; If the left son or right son pointer is empty, the report cannot find the corresponding keyword;

IfBThe number of left and right subtree nodes of all non-leaf nodes in the tree is almost (balanced), soBThe search performance of the tree approaches binary search, but it has the advantage of changingBTree Structure (insertion and deletion of nodes) does not need to move large segments of memory data, or even constant overhead;

For example:

HoweverBAfter multiple inserts and deletions, the tree may have different structures:

The right side is alsoBTree, but its search performance is linear. The same keyword set may lead to different tree indexes.BTree should also consider makingBThe tree maintains the structure of the Left graph, and avoids the structure of the right graph, that is, the so-called "balance" problem;

Actually usedBThe tree is in the originalBAdd balance on the basis of the treeAlgorithm, That is, "balanced binary tree"; how to maintainBA balanced algorithm for tree node distribution is the key to balancing Binary Trees.BPolicies for inserting and deleting nodes in the tree;

 

B-Tree

Is a multi-path search tree (not binary ):

1.Define any non-leaf node onlyMAndM> 2;

2.Root Node's number of sons[2, m];

3.Number of sons of non-leaf nodes except root nodes[M/2, m];

4.Each node must store at leastM/2-1(Rounded up) and upM-1Keywords; (at least2Keyword)

5.Number of non-leaf node keywords=Number of pointers to Son-1;

6. keywords for non-leaf nodes: K [1], K [2],..., K [M-1] ; and K [I] ;

7.Non-leaf node pointer:P [1], p [2],..., P [m]WhereP [1]Point to keyword lessK [1]Subtree,P [m]Point to keyword greaterK [M-1]Child tree, othersP [I]The pointing keyword belongs(K [I-1], K [I])Child tree;

8.All leaf nodes are on the same layer;

For example :(M = 3)

B-Tree search, starting from the root node, performs a binary search for the keyword (ordered) sequence in the node. If hit, it ends. Otherwise, the son node enters the range of the query keyword. duplicate, until the corresponding son pointer is null, or it is already a leaf node;

B-Features of the tree:

1.The set of keywords is distributed in the entire tree;

2.Any keyword appears only in one node;

3.The search may end at a non-leaf node;

4.Its search performance is equivalent to performing a binary search in the full set of keywords;

5.Automatic hierarchical control;

Because it limits non-leaf nodes except root nodesM/2To ensure the minimum utilization of the node, the minimum search performance is:

Where,MTo set the maximum number of Subtrees for non-leaf nodes,NIndicates the total number of keywords;

SoB-Tree performance is always equivalent to binary search (MNo value.BTree balance issues;

BecauseM/2When inserting a knot, if the node is full, split the node into twoM/2When you delete a nodeM/2Merge sibling nodes;

 

B +Tree

B +Tree isB-The variant of the tree is also a multi-path Search Tree:

1.Its definition is basically consistentB-Tree,:

2.The number of subtree pointers and keywords for non-leaf nodes is the same;

3.Sub-tree pointer of non-leaf nodesP [I], Pointing to the keyword value belongs[K [I], K [I + 1])Child tree (B-Tree is an open interval );

5.Adds a chain pointer to all leaf nodes;

6.All keywords appear at the leaf node;

For example :(M = 3)

B +Search andB-Tree is also basically the same, the difference isB +A tree hits only when it reaches the leaf node (B-A tree can be hit at a non-leaf node), and its performance is equivalent to performing a binary search in the full set of keywords;

B +Features:

1.All the keywords appear in the linked list of the leaf node (dense index), and the keywords in the linked list are exactly ordered;

2.It is impossible to hit non-leaf nodes;

3.Non-leaf nodes are equivalent to leaf node indexes (sparse indexes), and leaf nodes are equivalent to data layers that store (keywords) data;

4.More suitable for file index systems;

  

B *Tree

YesB +Tree variations, inB +The non-root and non-leaf nodes of the tree add pointers pointing to brothers;

B *The number of non-leaf node keywords defined in the tree must be at least(2/3) * mThat is, the minimum block usage is2/3(ReplaceB +Tree1/2);

B +Split the tree: When a node is full, allocate a new node and1/2Copy the data to the new node, and add a pointer to the new node in the parent node;B +Tree Splitting only affects the original node and the parent node, but does not affect the sibling node. Therefore, it does not need to point to the sibling node;

B *Split of a tree: When a node is full, if its next sibling node is not full, move part of the data to the sibling node, and then insert a keyword into the original node, finally, modify the keywords of the sibling node in the parent node (because the keyword range of the sibling node has changed). If the sibling node is full, add a new node between the original and sibling nodes and copy each node.1/3Data to the new node, and add a pointer to the new node at the parent node;

So,B *Probability Ratio of the new node allocated by the treeB +The tree should be low and the space usage should be higher;

  

Summary

BTree: Binary Tree. Each node stores only one keyword. If it is equal to or equal to, it hits. If it is less than the left node, it must be greater than the right node;

B-Tree: multi-path search tree, each node is storedM/2ToMKeywords. Non-leaf nodes store subnodes that point to the keyword range;

All keywords appear in the entire tree only once, and can be hit by non-leaf nodes;

B +Tree: InB-Add a linked list pointer to the leaf node based on the tree. All the keywords appear in the leaf node. Non-leaf nodes are used as the index of the leaf node;B +The tree always hits the leaf node;

B *Tree: InB +Add a linked list pointer for non-leaf Nodes Based on the tree, and change the minimum utilization of the node from1/2To2/3;

End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.