当前位置:网站首页>Tree, forest and transformation of binary tree

Tree, forest and transformation of binary tree

2022-06-22 19:56:00 Just one word

1. Convert normal tree to binary tree

 Insert picture description here

  • Add lines , Add a connection between all brother nodes . Insert picture description here

  • Off line , For every node in the tree , Only the connection between it and the first child node , Delete the connection between it and other child nodes . Insert picture description here

  • Level adjustment , Take the root node of the tree as the axis , Turn the whole tree clockwise for a certain angle , Make it structured
     Insert picture description here

2. The forest is converted into a binary tree

  • Convert each tree into a binary tree .

  • The first binary tree doesn't move , Start with the second tree , Take the root node of the last binary tree as the right child of the root node of the previous binary tree , Connect with wires .

3. Binary trees transform into forests 、 Common tree

Judge whether a binary tree can be converted into a tree or a forest , The standard is simple , That is, just look at whether the root node of this binary tree has a right child , Some are forests , If there is no tree, it is an ordinary tree .
 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here

原网站

版权声明
本文为[Just one word]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221828273268.html