当前位置:网站首页>(transformation) tree, binary tree and forest transformation principle
(transformation) tree, binary tree and forest transformation principle
2022-06-11 07:52:00 【zljun8210】
Tree to binary tree
The rule that a tree becomes a binary tree : The left pointer of each node points to its first child node . The right pointer points to its adjacent sibling nodes in the tree .
That is to say : Left child right brother .
No brothers at all , So the converted tree has no right subtree .
Specific operation :
- Connecting between brothers
- For each node , Only keep it with the first child node ( eldest son ) Connection of , All connections with other child nodes are erased .
- Take the root of the tree as the axis , Clockwise rotation 45 degree .

A binary tree becomes a tree
Rules for binary tree to tree : Is the inverse process of a tree becoming a binary tree . ask : Binary trees can be transformed into all kinds of trees , Why is this the only tree ? It is only assumed that the binary tree is derived from the above transformation algorithm , Then the process is reversible . So for a binary tree with a right subtree , You can't turn it into a tree in this way .
- Add lines . If a node has a left child , So take this left child's right child , The right child of the right child , Go straight down to the right , All connected to this node . In this algorithm, the correspondence tree becomes a binary tree, and the connection with the node other than the eldest child is erased , Now I want to find all my sons .
- Off line . Delete the connections between all nodes in the tree and these right children . I found my son , No one is allowed to have anything to do with them .
- Level adjustment .

Binary tree into forest
The rules :
- Recursive export : If the binary tree is not empty , Then the root of the binary tree and its left subtree are taken as the binary tree form of the first tree .
- recursive : Operate on the right subtree of a binary tree . That is, after removing a tree , Do the same for the rest of the binary tree , Until there is no right subtree .
Cut into a pile of binary trees , It's not over yet , The point is not binary tree , It's a tree , Therefore, use the above binary tree algorithm to turn the tree into a forest .

The forest becomes a binary tree
The rule is :
- First, turn each tree into a binary tree
- The root of the first tree is the root of the transformed binary tree
- The left subtree of the first tree is the left subtree of the root of the transformed binary tree
- The second tree is the right subtree of the binary tree
- The third tree is the right subtree of the right subtree of the binary tree
- …
The main points used here are : After converting to binary tree , This binary tree has no right subtree , So free your right hand to pick up a new tree , Therefore, it can connect many binary trees transformed from trees .
Compare this algorithm to the binary tree to forest , It's easy to understand , First cut down the root and its left subtree as a whole , Do the same for the rest of the section .

边栏推荐
猜你喜欢

放大镜子效果图

Import on CSDN MD file

Tidb cloud launched Google cloud marketplace, empowering global developers with a new stack of real-time HTAP databases
![[untitled] Weng_ C lesson 1](/img/4e/41876093ef6b6a38909832f89e1495.jpg)
[untitled] Weng_ C lesson 1

C language lesson 2

Zero foundation self-study SQL course | union joint query

Alchemy experience (model training of deep learning) the necessity of timely adjusting training parameters for some situations (the adjustment of learning rate LR is the primary) summarizes some metho

forEach 中 return 和 for 中 break

Summary of evaluation index knowledge points in target detection: summary of IOU cross overlap unit and map/ap/tp/fp/np
![[atcoder2306] rearranging (topology)](/img/b3/38589a07a7c26bea8ed154ab794760.png)
[atcoder2306] rearranging (topology)
随机推荐
[cluster] haproxy load balancing
Tidb Cloud est en ligne sur le marché Google Cloud pour permettre aux développeurs du monde entier d'utiliser une nouvelle pile de bases de données htap en temps réel
Sort - select sort
Lesson 1 about Xiaobai's C language
【HDU6357】Hills And Valleys(DP)
Request request object and response response object
pmp到底是什么?
排序——归并排序
Detailed explanation of shift operator and bit operator in C language
二本畢業,銀行外包測試工作 4 個月有餘。聊聊一些真實感受 ...
空间几何
Servlet、ServletConfig、ServletContext
Label the mask image not obtained through labelme
Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]
Opencv for face recognition
JSP technology: JSP overview, JSP basic syntax, JSP instructions, JSP implicit objects, JSP action elements
【软件测试】这样的简历已经刷掉了90%的面试者
20200802 T3 I always like [generating function exclusion, Lagrangian inversion]
Collation of basic knowledge of intermediate development of Andrews (for interview)
【IoT】项目管理:如何打造更好的跨职能团队?