Conversion between binary tree and each

Tree into a binary tree

(1) plus line. Plus a connection between all the sibling nodes.

(2) to the wire. Each node in the tree, leaving only its connection with the first child node, delete the connection between it and the other child nodes.

(3) level adjustment. To the root of the tree as the axis, the angle of rotation clockwise whole tree, so that the structure structured. (Note that the first child is left child node, brothers conversion over children is the right child node)

                       

Forest converted to a binary tree

(1) to convert each binary tree.

(2) fixed on a binary tree, starting from the second binary tree, the binary tree sequentially to the right child of the root node as a root node of a binary tree before, with the connecting lines.

 

Converted into a binary tree

It is converted into a binary tree of the reverse process.

(1) plus line. If the left child node of a node X exists, then the left child of the right child node, right child of the right child node, right child of the right child of the right child nodes ..., both as a child node of X . The node with the node X and the line connecting the right child.

(2) to the wire. Delete the original binary tree nodes to connect all of its right child nodes.

(3) level adjustment.

 

Converted into a binary tree forest

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

(1) starting from the root, if the right child exists, put the connection with the right child nodes removed. Check again after the separation of a binary tree, its root if the right child exists, delete ... connection. Until the root of all these children with the right connections are deleted.

(2) converting the separated binary tree each of them.

 

Guess you like

Origin www.cnblogs.com/Virus-Faker/p/11850964.html
Recommended