1. Concept
The structure of a binary tree node:
Class node{ int value; //value indicates the node value of the binary tree Node left; Node right; //left and right represent two children of a binary tree Node (int data) { this.value = data; }}
2. Two fork number traversal 2.1 sequentially traverse the binary tree
- First Order traversal: Middle, left, and right
- Middle sequence traversal: Left, middle, and right
- Post-post traversal: Left, right, middle
- Take a two-fork tree as an example:
- The result of the first order traversal is: 1, 2,4,5,3,6,7
- The result of the middle sequence traversal is: 4,2,5,1,6,3,7
- Post-order traversal results are: 4,5,2,6,7,3,1
2.2 Traversing a binary tree by layer
- The width-first traversal of the binary tree;
- Width-first traversal often uses queue structure;
- (often asked to print along with the companion number!!) )
3. Balanced binary tree (AVL tree)
Concept:
- The empty tree is a balanced binary tree;
- If a tree is not empty, and all of its subtrees satisfy their respective Zuozi and right sub-tree height difference is not more than 1, is a balanced binary tree;
-
-
- (Balanced binary tree)
- (Unbalanced binary tree)
- Because, for, in the 2 nodes of the subtree, the left subtree is 2, the right subtree is 0, the height difference is greater than 1, I am therefore not balanced binary tree;
4. Search for binary trees
Search for binary tree features:
The head node values for each subtrees tree are larger than the values of all nodes on the respective left subtree, and are smaller than the values of all nodes on the respective right subtree.
- Search binary tree According to the sequence of sequential traversal, must be from small to large arrangement.
- Among them, the red black tree/Balanced binary tree (AVL tree), etc., are different implementations of the search binary tree.
5. Full two fork Tree
Concept: Full Two forks the tree is a node with two child nodes on each layer except the last node without any child nodes.
The number of layers in the two-ary tree is L, and the node points are N, then N=2L-1;L=LOG2 (n+1).
5. Complete binary Tree
Concept: In addition to the last layer, each of the other layers of the number of nodes are full, the last layer if also full, is a full two fork tree, is also a complete binary tree. If the last layer is dissatisfied, the missing nodes are all concentrated on the right, and that is a tree full of two forks.
As below, are completely binary tree!!!
Data structures and Algorithms (5)-----> Two fork Trees