tree to binary tree, forest to binary tree, binary tree to forest

Convert tree to binary tree

(1) Add line. Add a line between all sibling nodes.

(2) Go to line. For each node in the tree, only the connection between it and the first child node is kept, and the connection between it and other child nodes is deleted.

(3) Level adjustment. Taking the root node of the tree as the axis, rotate the whole tree clockwise by a certain angle to make the structure clear. (Note that the first child is the left child of the node, and the child converted by the brother is the right child of the node)

                       

Convert forest to binary tree

(1) Convert each tree to a binary tree.

(2) The first binary tree does not move. Starting from the second binary tree, the root node of the latter binary tree is used as the right child of the root node of the former binary tree, and the lines are connected.

 

Convert binary tree to tree

is the inverse process of converting a tree to a binary tree.

(1) Add line. If the left child node of a node X exists, the right child node of the left child, the right child node of the right child, the right child node of the right child's right child... are all regarded as the child of node X . Connect node X to these right child nodes with lines.

(2) Go to line. Delete all nodes in the original binary tree and their right child nodes.

(3) Level adjustment.

 

Convert binary tree to forest

If the root node of a binary tree has a right child, the binary tree can be converted into a forest, otherwise it will be converted into a tree.

(1) Starting from the root node, if the right child exists, delete the connection with the right child node. Then look at the separated binary tree, if the right child of the root node exists, then delete the connection. . . until all the connections between the root node and the right child are removed.

(2) Convert each separated binary tree into a tree.

 


http://www.cnblogs.com/zhuyf87/archive/2012/11/04/2753950.html

Guess you like

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