tree of data structures

Tree

Tree traversal: All are based on the order in which the root node is traversed, divided into pre-order, in-order, post-order, and then the left node first, then the right node.
1: In-order traversal: left root right (traverse from left node, then root node, then right node, the same below)
2: Pre-order traversal: root left and right
3: Post-order traversal: left and right roots

1: Ordinary binary tree: Each node has at most 2 subtrees.
a. Full binary tree: All nodes on each level have two children, except the last level has no children.
b. Complete binary tree: only the lowermost two layers of node degree can be less than 2, and the nodes of the lowermost layer are concentrated in the leftmost position of the layer.

2: Binary search tree: For each node X in the tree, the value of all items in its left subtree is less than the value in X, and the value of all items in its right subtree is greater than the value in X. (lvalue < root value < rvalue).
Time complexity: The time complexity of insertion and lookup is O(logn), but in the worst case there will still be O(n) time complexity (the reason is that the tree is not balanced when inserting and deleting elements ).

3: AVL tree of balanced binary tree: it is an empty tree or the absolute value of the height difference between its left and right subtrees does not exceed 1 (level difference <=1), and both left and right subtrees are a balanced binary tree, At the same time, a balanced binary tree must be a binary search tree, but not necessarily vice versa.
Time complexity: The time complexity of insertion, search, and deletion is maintained at O(logN) in the best and worst cases.
Note: When a balanced binary tree performs insertion and deletion operations, in order to maintain balance, a self-balancing operation—rotation (left-hand and right-hand) will be performed.

4: Red-black tree of balanced binary tree: a binary search tree with a color attribute for each node, the color is red or black.
Features:
Property 1: Nodes are red or black. 
Property 2: The root is black. 
Property 3: All leaves are black (leaves are NIL nodes).
Property 4: Every red node must have two black children. (All paths from each leaf to the root cannot have two consecutive red nodes.) 
Property 5: All simple paths from any node to each of its leaves contain the same number of black nodes.
Time complexity: Searches, insertions and deletions can be done in O(logn) time, where n is the number of elements in the tree.
Note: Red-black trees have left-handed, right-handed and coloring problems.

5: B-tree (B-tree): It is a balanced tree for search, but it is not a binary tree.
The difference between the B-tree and the balanced binary tree is that the B-tree is a multi-fork tree, also known as a balanced multi-path search tree (more than two search paths), that is, there are more than 2 bytes under a node.
Time Complexity: O(log n) time complexity runs for lookups, sequential reads, insertions and deletions.
Note: A large number of data structures of B-trees and B+ trees are used in the database indexing technology, and the file system is also mostly this data structure.

6: The same is true for the time complexity of B+ trees and B* trees.

For details, see: http://blog.jobbole.com/111680/
Hadron Blog: https://blog.51cloud.win/2017/12/16/%E6%A0%91%E4%B8%8E%E6% 95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326227961&siteId=291194637