"Data Structure - binary tree"

One: What is the binary tree?

  - concept

    - a limited binding n (n> 0) of nodes, the set or a null set.

    - or by a binary tree and a root node are referred to as two disjoint left subtree root node and the right subtree of the composition.

 

  - defined
    - at most two sub-tree each node, so the absence of binary tree nodes is greater than 2. (No sub-tree / tree of a child is also possible)

    - left subtree and right subtree is in order, it can not be reversed.

    - Even if a node in the tree, only a sub-tree, but also need to distinguish between the left or right subtree subtree.

 

  - Nature

    - at most 2 (i-1) th node in the i-th layer of the binary tree.

    - k is a binary tree in a depth of at most 2 (k) -1 nodes.

 


Two: What is the empty binary tree?

  - Definition

    - number of nodes (n = 0) is the empty binary tree.

 

 


Three: What is oblique tree?

  - Definition

    - All the sub-tree nodes only the left / right subtree only.

 

 


Four: What is the full binary tree?

  - Definition

    - all the branches of the nodes left and right subtrees are present, and the leaf nodes on the same layer.

    - the degree of non-leaf nodes must be 2

  - illustration

    -

 


Five: What is a complete binary tree?

  - Definition

    - If h is the depth of a binary tree, except the h layer, other layers (1 ~ h-1) has reached the maximum number of nodes, the h layer all nodes are continuously concentrated in the left, which is entirely binary Tree.

 

  - Features

    - full binary tree complete binary tree is a special, but not necessarily a complete binary tree is a full binary tree.


  - illustration

    -


Six: What is (BST) binary search tree?

  - concept

    - binary search tree is also known as a binary search tree.

 

  - Definition

    - First, it is a binary tree, each node in the tree when N, the value of its left subtree nodes are all less than the value of the node N, the value of the right subtree node is greater than the value of the node N.

 

  - illustration

    -
 


Seven: What is (AVL balanced binary tree)?

  - Why AVL balanced binary tree?

    - searching efficiency can be improved binary search tree, to a certain extent, but when the original sequence of ordered binary tree degenerate into a single list, search efficiency is reduced to O (n).

      -

    - Find efficient binary search tree depends on the height of the tree, so keeping the minimum height of the tree, you can look for to ensure the efficiency of the tree.
      -

    
    - when the number of nodes can be seen that some, holding left and right ends of the tree balance maximum search efficiency tree.

    - a left and right subtrees height by no more than 1 balanced binary tree.

 

  - Definition

    - can be an empty tree.

    - if not empty tree, any left subtree of a node with a right subtree are balanced binary tree, and the absolute value of the difference between the height of not more than 1.

 

  - Detailed

    - https://www.cnblogs.com/fivestudy/p/10348045.html


Eight: What is the B- tree?

  - Why have a B- tree?

    - time complexity of binary search tree query is O (logN), to find the fastest and least number of comparisons

    - Since the performance has been so good, but why is achieved using B-Tree indexes rather than a binary search tree, the key factor is the number of disk IO.

      - database index is on the disk, when the size of the table larger than the data, the index also followed the growth of storage, reach several G even more.

      - When we use the index query, it is impossible to index all loaded into memory, can only be loaded one by one page per disk, where disk page on the corresponding node of the index tree.

    - analysis of the situation, to reduce the number of disk IO must be compressed height of the tree, so the tree lanky try to become chunky tree, so B-Tree was born in such a great background.

 

  - Definition

    - m-order B-Tree satisfies the following conditions

      - each subtree with the most nodes m

      - There are at least two sub-tree root

      - branch node has at least m / 2 units sub tree (except the root node and the leaf nodes are branch nodes)

      - all leaf nodes are in the same layer, each node can have up to m-1 th key, and in ascending order.

 

  - Benefits

    - the same amount of data, B- tree compressed height of the entire tree, the disk I / O less.

    - leaf node can hold more data, more nodes receiving element.

 

  - icon (step 3 B- tree)

    -

 

 

  - Detailed

    - https://www.cnblogs.com/dongguacai/p/7239599.html



Nine: What is a B + tree?

  - Why have a B + tree?

    - B- tree is commonly used as an index, but the face of large volumes of data, the class B- tree is large, look for performance degradation.

    - B + Tree is a variant of the B-tree, the query has higher performance than the B-tree. B- may be based on the compression height of the tree, reducing the I / O.

 

  - Definition

    - at m sub-nodes of the tree contains m elements (B-Tree is m-1)

    - root and branch nodes do not hold data only for the index, all data is stored in the leaf nodes.

    - all the branches of the nodes and the root node are simultaneously present in the child node, it is the largest or smallest element in the child element node.

    - leaf node will contain all the keywords and links to the data record pointer, and the leaf node itself is based on the size of the keywords in ascending order link.

 

  - Advantages of B +

    - B + tree nodes do not store (real data), the same size of disk page elements can accommodate more nodes at the same amount of data, B + tree to be relatively more squat more, more number of disk IO less.

    - Since only the leaf nodes are not saved satellite data, B + tree leaf node to each query must; and a B-tree is not the same for each query, the best case is the root node, the worst case is a leaf node, there is no B + tree stable.

    - cis formed leaf node list, find better performance range.

 

  - Detailed

    - https://www.cnblogs.com/dongguacai/p/7241860.html

 

  - illustration

    - 

 

Ten: What is (RBT) red-black tree?

  - Why have a red-black tree?

    - searching efficiency can be improved binary search tree, to a certain extent, but when the original sequence of ordered binary tree degenerate into a single list, search efficiency is reduced to O (n).

    - In order to address the imbalance new node is inserted into the binary tree repeatedly caused.

 

  - newly inserted node default What color?

    - the nature of the red-black tree we know about red-black tree of black sub-tree of equal height.

    - If the newly inserted node default setting is black, is bound to undermine the left and right sub-tree of black high equivalent characteristics.

    - At this point, then adjust the red-black tree, will be rather cumbersome.

    - If the newly inserted node will default to red, it will not destroy the existing state equal high black, we only need to address the red nodes around the child must be a problem to black nodes.

    - So, the newly inserted red-black tree node, the default setting is red.

 

  - Adjust the red-black tree way?

    - color / rotation

 

  - black trees and balanced binary difference?

    - a red-black tree that is balanced binary tree.

    - but it's a sign to pay more for each node attributes for adding and deleting nodes.

    - with respect to the balanced binary tree, the better the performance increase in red-black tree / delete nodes.

    - the difference between red-black tree and B- tree?

    - both are ordered data structure, used as a data container.

    - red-black tree is used in internal sorts, that was placed in memory, internal Microsoft STL map and set of implementation is red-black tree.

    - B Tree is used in memory does not fit, when most of the data stored in the external memory. B-tree because fewer layers, so you can ensure that each operation, the number of disk reads as small as possible.

    - When the data is small, can completely into memory, time complexity is lower than the red-black tree B-tree.

    - Conversely, a large amount of data, when the external memory is dominant, B tree because of less number of disk reads, having faster.

 

  - Definition

    - node is red or black.

    - the root is black.

    - each leaf node are black empty node (NIL node).

    - two child nodes each red node are black. (Leaf from each of two consecutive red can not have all the nodes on the path to the root).

    - from any node to all leaves of each path contains the same number of black nodes.

Guess you like

Origin www.cnblogs.com/25-lH/p/11011914.html