Balanced binary tree, B-tree, + + tree, b* Tree understand one of them, and you'll understand.

Source: Internet
Author: User

1. Balanced binary Tree

(1) Origin: Balanced binary tree is a binary tree based on the strategy to improve data search speed of the data structure of two trees;

(2) Features:

The Balanced binary tree is the data that the data is assembled into a tree structure by the method of dichotomy thinking, which reduces the retrieval of irrelevant data by using the data of the tree structure, and greatly improves the speed of data retrieval. The structure of balanced binary tree The assembly process has the following rules:

Non-leaf node can only allow up to two child nodes, each non-leaf node data distribution rules for the left sub-node small current node value, the right child node is greater than the current node value (here the value is based on its own algorithm rules, such as hash value);

Balanced tree hierarchy: Because the balance binary tree query performance and the tree hierarchy (h height) is inversely proportional to the lower H value query faster, in order to ensure that the structure of the tree is roughly balanced between the two ends of the data to reduce the two-tree query difficulty generally using an algorithm mechanism to achieve the balance of node data structure, such as AVL, Treap, red and black trees, the use of balanced binary tree can ensure that the data of the left and right sides of the node level difference will not be greater than 1., by this way to avoid the tree structure as a result of the deletion of the linear linked list effect query efficiency, to ensure the data balance in the case of finding data near the binary search;

Summarize balanced binary tree features:

(1) The non-leaf node has a maximum of two sub-nodes;

(2) The non-leaf node value is greater than the left child, less than the right child node;

(3) The level of the left and right sides of the tree will not be greater than 1;

(4) A node with no value equal to repeat;

2. B-Tree (B-tree)

Note: Before there are many articles to understand B-tree and b-tree into two different types of trees, in fact, these two are the same tree;

1, Concept: B-tree and balanced binary tree slightly different is a B-tree is a multi-fork tree aka balanced Multi-Path search tree (find the path of more than two), database indexing technology in the large number of users B-tree and + + Tree data structure, let us see what his characteristics;

2. Rules:

(1) Each node of the tree species has a maximum of M child nodes and m>=2, except for the empty tree (note: M-order represents a tree node up to how many search paths, M-order =m Road, when m=2 is 2 fork tree, m=3 is 3 fork);

(2) The key word count of each node outside the root node is greater than or equal to Ceil (M/2)-1 is less than or equal to m-1, the key words of the non-root node must be >=2; (Note: Ceil () is a function of rounding in the positive infinity direction such as ceil (1.1) result 2)

(3) All leaf nodes are in the same layer, and the leaf nodes have pointers to their child nodes in addition to the keywords and key record pointers except that their pointer addresses are NULL for the last layer of the empty lattice

(4) If a non-leaf node has n child nodes, the key word count of the node equals N-1;

(5) All node keywords are listed in ascending order, and follow the left small right large principle;

Finally, we use a graph and a practical example to understand the B-tree (here for ease of understanding I will directly use the actual letter size to arrange C>b>a)

3, B-Tree query process: If I want to find the e-letter, the search process is as follows

(1) To obtain the root node of the keyword comparison, the current root node keyword is m,e to less than M (26 alphabetical order), so to find the child node to the left (the dichotomy rule, left small right large, the left side is less than the current node value of the child node, the right is magnified in the current node value of the child node);

(2) Get the keyword D and g,d<e<g so directly find the middle node D and G;

(3) Get E and F, because e=e so directly return the keyword and pointer information (such as the tree structure does not contain the node you want to find to return null);

4, B-Tree insertion node process

Define a 5-order tree (balancing the 5-way lookup tree;) and now we are going to build a 31-order tree out of 3, 8, 11, 23, 29, 50, 28, 5;

Follow the rules:

(1) is currently to form a 5-way search tree, then at this time, the key words must be greater than or equal to Ceil (5/2)-1 is less than or equal to 5-1 (the key words less than CEI (5/2)-1 will be m=5 node merging, greater than 5-1 will be split node, non-root node key words >=2);

(2) To satisfy the node itself is larger than the left node, smaller than the right node collation;

5, B-tree node deletion

Rules:

(1) is currently to form a 5-way search tree, then at this time m=5, the key word number must be greater than or equal to CEI (5/2) 1, less than or equal to 5-1, non-root node key words greater than 2;

(2) To satisfy the node itself is larger than the left node, smaller than the right node collation;

(3) The key word number is less than two, first from the child node, the child node does not meet the criteria to take to the parent node, take the middle value toward the parent node;

3. Features:

The B-tree is different from the balanced binary tree, each node contains more keywords, especially when the B-tree is applied to the database, the database makes full use of the principle of disk block (disk data storage is stored in the form of blocks, each block size is 4K, each IO for data reading, The data of the same disk block can be read out at once) to limit the size of the node and make full use of the size of the disk; The tree has more nodes than the original two-fork tree, reducing the number and complexity of data lookup;

3. B + Tree

B + Tree is an upgraded version of the second tree, compared to the B-tree to better utilize the space of the node, so that the query speed is more stable, its speed is completely close to the dichotomy of the search. Why is it that B + tree search is more efficient and more stable than that of the trees? Let's take a look at the difference.

(1) The non-leaf nodes of the B + + tree are not saved with a pointer to the keyword record, so that the key words that can be saved by each node of the C + tree are greatly increased;

(2) b + Tree leaf node saves the parent node all keywords and keyword record pointers, each leaf node keyword from small to large links;

(3) The number of root node keywords of B + tree is equal to that of its child nodes;

(4) B + non-leaf node only data index, not the actual keyword record pointer, all the data address must be to the leaf node to obtain, so each data query the same number of times;

Characteristics:

On the basis of the B-tree, each node stores more key words, the tree hierarchy is less so query data faster, all refers to the keyword pointer has a leaf node, so the number of each search is the same, so the query speed more stable;

4. b* Tree

The b* tree is a variant of B + tree, which differs from the B + tree in the following ways:

(1) First is the number of keywords limit problem, B + Tree initialization keyword initialization number is CEI (M/2), b* tree initialization number is (CEI (2/3*M))

(2) B + Tree node will be split when full, and the b* tree node is full to check if the sibling node is full (because each node has a pointer to the brother), if the sibling node is not full to the sibling node to transfer the keyword, if the sibling node is full, the current node and the sibling node 1/3 of the data to create a new node ;

Characteristics:

On the basis of the B + tree, the capacity of its initialization becomes larger, the node space utilization is higher, and the pointer of the sibling node can be transferred to the sibling node, which makes the number of b* tree amount decomposition less.

Summary: From the balance of binary tree, B-tree, + + tree, b* tree overall view of their implementation of the idea is the same, are using dichotomy and data balance strategy to improve the speed of finding data;

The difference is that they are one in the process of evolution through the IO from the disk to read the principle of a step-by-step evolution, each evolution is to make the node more reasonable use of space, so that the tree hierarchy reduced to achieve the purpose of rapid search data;

If you don't understand it, it is recommended that the following information be described in detail:

Complementary concepts:

With one (binary search): Binary search principle-the column of knowledge

With two (b-Plus, b*-tree): from B-tree, + + tree, b* tree to R-Tree

Attached to the three (B, C +, b* tree):end& #x27; s coding life

Source of reprint--https://zhuanlan.zhihu.com/p/27700617

Balanced binary tree, B-tree, + + tree, b* Tree understand one of them, and you'll understand.

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.