Tree and binary tree analysis, Binary Tree Analysis
A tree is a connected undirected graph that does not contain loops.
There is a tree on the left, and a figure on the right, because there is no loop on the left, and there is a loop like 1-2-5-3-1 on the right.
Tree features:
1. Any two nodes in a tree have only one path connected;
2. If a tree has n nodes, it must have n-1 edges;
3. Adding an edge to a tree will constitute a loop.
A tree is an undirected graph with only one path between any two nodes. Only connected undirected graphs without loops are trees.
Root Node. A tree has only one root node. Parent node, child node. A node without a subnode is called a leaf node.
Depth: the number of layers from the root node to the node (the root layer is the first layer ).
Binary Tree
Binary Tree Features: each node can have at most two sons: The left son and the right son, or each node can have at most two trees.
The binary tree is either empty or composed of the root node, left subtree, and right subtree.
Full Binary Tree: Each internal node (neither the root node nor the leaf node) in a binary tree has two sons, or all the leaf nodes in the full binary tree have the same depth. Depth h with 2 ^ h-1 nodes.
Complete Binary Tree:In addition to one or more leaf nodes missing in the rightmost position, the other nodes are plump. The height is h. Except for layer h, other layers (1 ~ H-1) to the maximum number of nodes. If a node has a right son, it must also have a left son.
In a Complete Binary Tree, if a parent node number is k, the left son number is 2 * k, and the right son number is 2 * k + 1. if it is known that the son (either left or right) number is x, its parent node number is x/2.
If a full binary tree has N nodes, the height of the Complete Binary Tree is log2N or logN, that is, there are at most logN layer nodes.