1. convert a tree to a binary tree
1. Add a line between all the sibling nodes with the same parent nodes in the tree;
2. Keep the line between the newly added node and the left sibling node and delete the line between the node and the parent node instead of the first child node in the tree.
3. Sort all the reserved and added connections so that the first child node of each node is located at the left child pointer, so that the right brother node of each node is located at the right child pointer.
2. Restore a binary tree to a tree
How to restore a binary tree to a tree:
1. if a node is the left child of its parent node, the right child of the node and the right child of the right child ...... are connected to the parent node of the node with a line
2. Delete connections between all parent nodes in the original binary tree and the right child
3. Sort all reserved and added connections so that all child nodes of each node are located at the same tree level.
3. tree traversal
First root traversal, then root Traversal
First root traversal:
1. Access the root node; 2. Traverse each subtree of the root node in the order from left to right
Root traversal:
1. In the left-to-right order, each subtree of the root node is traversed by the root node.
2. Access the root node
Note:
1. The first root traversal sequence of the tree must be the same as the first traversal sequence of the Binary Tree converted by the tree.
2. The post-root traversal sequence of the tree must be the same as the central traversal sequence of the Binary Tree converted by the tree.
Tree and binary tree Conversion