Database Design Principle [B tree, B-tree, B + tree]

Source: Internet
Author: User

B treeThat is, the binary search tree:

1. All non-leaf nodes have at most two sons (left and right );

2. All nodes store a keyword;

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;

 

B-tree search starts 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;

 

B-treeIs a multi-path search tree (not binary ):

1. Define any non-leaf node with a maximum of M sons; and M> 2;

2. The number of sons at the root node is [2, m].

3. The number of non-leaf nodes except the root node is [m/2, m];

4. Each node holds at least m/2-1 (rounded up) and at most M-1 keywords; (at least 2 keywords)

5. Number of keywords for non-leaf nodes = number of pointers to Son-1;

6. Non-leaf node keywords: K [1], K [2],…, K [M-1]; and K [I] <K [I + 1];

7. Non-leaf node pointer: P [1], p [2],…, P [m]; where P [1] points to a subtree with a keyword less than K [1], p [m] points to a subtree with a keyword greater than K [M-1, other P [I] points to the subtree where the keyword belongs (K [I-1], K [I;

8. All leaf nodes are on the same layer;

 

B-tree search: starts from the root node and performs a binary search for the keyword (ordered) sequence in the node. If hit, the query ends. Otherwise, the son node in the search keyword range is entered; repeat until the corresponding son pointer is null or is already a leaf node;
 

B + treeThe B + tree is a variant of the B-tree and also a multi-path Search Tree:

1. Its definition is basically the same as that of B-tree,:

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

3. the subtree pointer P [I] for non-leaf nodes, pointing to the subtree with the key value [K [I], K [I + 1]) (B-tree is an open interval );

5. Add a chain pointer to all leaf nodes;

6. All keywords appear at the leaf node;

 

The search for B + is basically the same as that for B-trees. The difference is that B + trees hit only when they reach the leaf node (B-trees can hit non-leaf nodes ), its performance is also equivalent to performing a binary search in the full set of keywords;

 

 

 

 

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.