Red-Black Tree B-Tree B + Tree Database index

Source: Internet
Author: User

Red-black tree, is a special nature of the two-fork search tree,

node, either red or black

The root node is black.

The leaf node is black.

If a node is red, then its two sons are black

For any node, each path of its leaf node tree trailing NIL pointer contains a black node of the same data

When inserting or deleting nodes, it is possible to change the nature of the red-black tree, which needs to be adjusted to keep the nature, and the commonly used operations are left-and right-handed

The left and right spins of the red and black trees:

L- pivot:

pivot-y is the axis,y is called the new root node, andy 's Zuozi is called the right subtree of pivot.

Right-handed pivot:

With pivot-y as the axis,y is called the new root, andpivot is the new right subtree of y

B-Tree (B. tree)

B-Tree with order definition

B-Tree is also called balanced multi-path search tree. A treeMOrder ofBTree(Note: Do not simply think of a treeMb tree is m fork tree, although there are Span lang= "ZH-CN" > Quad tree , octal tree kd tree vp/r tree /r* tree Span lang= "en-US" >/r+ tree /x tree /m tree / segment tree / Hilbert r tree / priority r Tree and other space division tree, but with b tree is not equivalent to ) The characteristics of

Each node in the tree contains a maximum of M children (m>=2);

Root nodes and leaf nodes, each of the other nodes has at least [Ceil (M/2)] Children (where ceil (x) is an upper-bound function);

Joghen nodes are not leaf nodes, there are at least 2 children (special case: No Child root node, that is, the root node is a leaf node, the whole tree has only one root);

All leaf nodes appear on the same layer, and the leaf nodes do not contain any keyword information (it can be seen as an external contact or a contact where the query failed, in fact these nodes do not exist, pointers to these nodes are null); (Reader feedback @ rengat: There is a mistake here, the leaf node is just a pointer without children and pointing to the child, These nodes also exist, and there are elements. @ Researcher July: In fact, the key is to think of what as a leaf node, because, as in the red and black tree, each null pointer as a leaf knot, but did not draw it out.

Each non-terminal node contains n keyword information: (N,P0,K1,P1,K2,P2,......,KN,PN). which
A) Ki (I=1...N) is the keyword, and the keyword is sorted in ascending order of K (i-1) < Ki.
b) Pi is a contact point pointing to Subtree, and the key of the pointer P (i-1) to all nodes of the subtree is less than Ki, but both are greater than K (i-1).
c) The number of keywords n must satisfy: [Ceil (M/2) -1]<= n <= m-1.

B + Tree: A variant of the B. Tree

The similarities and differences of M- order b + Tree

n the nodes of a subtree contain n-1 keywords

All the keyword information is on the leaf node.

Non-endpoints can be viewed as indexes

Leaf nodes from small to large sequential links

Why The B + Tree is more suitable as a file index and database index in the operating system

1.b+ trees have lower disk read and write costs

The internal nodes are smaller, and in the same block, the internal nodes can be stored more, and the more keywords that need to be looked into in memory at once.

Each node of the B-tree is stored in the form of key_address, while the non-leaf nodes of the + + tree only need to store key,address information to be placed on the leaf nodes. Therefore, when searching, the data block can contain more nodes and improve the retrieval efficiency.

2. More stable query efficiency

Each query needs to be from the root node to the leaf node

3. Leaf node from left to right link, according to the principle of locality, convenient to load the data around

Red-Black Tree B-Tree B + Tree Database index

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.