当前位置:网站首页>(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 .

边栏推荐
- Wc2020 guessing game
- Zero foundation self-study SQL course | outer join external connection
- 自定义ViewGroup的知识点总结-持续更新
- Detailed explanation of character function and string function (including simulation implementation)
- [poj3691] DNA repair (AC automata +dp)
- ConstraintLayout中使用Guideline限制控件最大宽度
- Euler's theorem and its extension (with proof)
- [atcoder2376] black and white tree (game)
- Session and session management technology
- 二本毕业,银行外包测试工作 4 个月有余。聊聊一些真实感受 ...
猜你喜欢

Figure seamless database integration tushare interface

C- print 99 multiplication table

Batch splice string

Storage of floating point in memory

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

wordcloud的使用

如何准备PMP新版大纲考试?

学习《缠解论语》
![[untitled] Weng_ C lesson 1](/img/4e/41876093ef6b6a38909832f89e1495.jpg)
[untitled] Weng_ C lesson 1

A detailed explanation of one of the causes of dead loop caused by array out of bounds in C language
随机推荐
图数据库无缝集成Tushare接口
远程办公经验分享 | 社区征文
2021-11-05 definition of cache
Detailed explanation of shift operator and bit operator in C language
Flask页面的分页
2021-10-24
[IOT] intelligent hardware: how to obtain the WiFi signal strength of hardware products
Switch statement
Qunhui ds918 creates m.2 SSD read / write cache
YUV数据的裁剪与重叠
Zero foundation self-study SQL course | outer join external connection
如何准备PMP新版大纲考试?
自定义ViewGroup的知识点总结-持续更新
Tutoriel de démarrage bladed (vidéo)
C. Manipulating History(贪心/哈希/思维/好题)
multi-sig SC
Sort - Swap sort
Request request object and response response object
[cluster] lvs+keepalived high availability cluster
Wc2020 course selection