Summary of tree knowledge points

What is a tree?

Answer: A tree is a collection of n nodes.

 

What is a forest?

Answer: A set of n disjoint trees is called a forest.

 

What does the degree of a node mean?

Answer: The number of subtrees a node has.

 

What is the height (depth) of a tree?

Answer: The maximum level of nodes in the tree.

 

What is the average depth of the tree?

Answer: O(logN) .

 

What is a binary tree?

Answer: A binary tree is a tree whose each node has at most 2 children .

 

What is a binary search tree ( ADT )?

Answer: A binary search tree is a tree in which all nodes in the left subtree have values ​​less than the root node, and all nodes in the right subtree have values ​​greater than the root node.

       The binary search tree guarantees the order of the elements.

 

What is a balanced binary search tree ( AVL )?

Answer: AVL is a binary search tree with a balanced condition. The height difference between the left subtree and the right subtree of each node is at most 1 .

  Balanced binary search tree ( AVL ) adds a balance condition to the binary search tree to prevent the level of the binary search tree from being too deep when searching.

  When inserting or removing elements from the AVL tree, the equilibrium condition may be violated, and the solution is to rotate. There are four kinds of rotations: LL type balance rotation, RR type balance rotation, LR type balance rotation, RL type balance rotation, these four rotations can be summarized into two types: single rotation and double rotation. If the balance of AVL is destroyed when inserting or deleting elements into the AVL tree , it needs to be adjusted by rotation to rebalance.

 

What is a red-black tree?

Answer: First of all, the red-black tree is a binary search tree, and some features are added on the basis of the binary search tree.

 

  A binary search tree stores elements in a certain order, which makes it convenient to find elements, and has an average depth of O(logN) . But the problem with binary search trees is that their performance is heavily dependent on the input, which is random. If this is not the case, the running time increases significantly and the binary search tree becomes an expensive linked list.

  Balanced binary search tree ( AVL ) is used to solve the problem of binary search tree. It requires that the height difference between the left subtree and the right subtree of all nodes is at most 1 , which ensures that the tree is not too deep. However, the balanced binary search tree ( AVL ) has too strict requirements on balance, so that it is very easy to destroy the balance condition during insertion and deletion operations, which will cause frequent balance adjustment, resulting in decreased efficiency.

  The red-black tree is a compromise choice. It can play a balancing role, so that the depth of the binary search tree is not too deep, and it is not as severe as the balanced binary search tree ( AVL ). What it pursues is The local balance of the binary search tree, even in the insertion and deletion operations, will not destroy the balance condition of the red-black tree so easily, and the efficiency is higher than that of AVL .

 

A red-black tree is a binary search tree with coloring properties, and its characteristics are as follows:

Answer: 1. Each node is either colored red or black.

       2. The roots are black.

       3. If a node is red, then its children must be black.

       4. Every path from a node to a null reference must contain the same number of black nodes.

 

 

 

 

 

Guess you like

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