STL notes-B tree, B + tree, Rb tree

Source: Internet
Author: User

I. Red/black tree (RB-tree)

The red/black tree is a balanced binary search tree with 'color' features on each node..

In addition to the conditions for balancing Binary Trees, it also has the following features:

1) The Node color is red or black;

2) the color of the root node is black;

3) if a node has a red attribute, its subnodes must be black;

4) All leaf nodes are black (the leaf node is null );

5) from any node to all simple paths of its leaf (null) node, contains the same number of black nodes.

The sgi stl containers based on the red and black trees include: Set, MAP, Multiset, and multimap..

 

II. B tree

B is a balanced multi-Cross Tree.Generally, the M-Level B tree should meet these conditions:

1) each node can have up to M subnodes;

2) Apart from root nodes and leaf nodes, each node must have at least [Ceil (M/2)] subnodes. Ceil () is the upper limit function;

3) All leaf nodes are on the same layer, and leaf nodes do not contain any keyword information;

4) Non-leaf nodes with n key codes exactly have n + 1 subnodes.

Tree B is mostly used for index Implementation of disk databases.

3. B + tree

The B + tree is a variant of the B tree and also a multi-cross search tree.. The main difference between B and B is:

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

2) adjacent subtree pointers of non-leaf nodes P [I] and P [J], p [I] Point to key value V [I] ~ Between V [J-1;

3) All the keyword information to be searched is stored in the leaf node, and the linked list pointer is added between them. Non-leaf nodes are only part of the index, that is to say, only leaf nodes can be searched.

Adding a linked list pointer to the leaf node in the B + tree facilitates the fission or merging operations caused by element insertion or deletion.The B + tree is more suitable for file index systems.

 

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.