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

边栏推荐
猜你喜欢

签到体系设计:签到功能该怎么画

Summary of evaluation index knowledge points in target detection: summary of IOU cross overlap unit and map/ap/tp/fp/np

Bladed入门教程(视频)

C language - Growth Diary -03- function definition and function prototype declaration

About static keyword

Batch splice string

C language to achieve a simple game - minesweeping

空间几何

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

安卓初中级开发基础知识整理(面试自用)
随机推荐
Qunhui ds918 creates m.2 SSD read / write cache
Lesson 1 about Xiaobai's C language
2. Graduated from this course, and the bank has outsourced testing work for more than 4 months. Talk about some real feelings
You got 8K in the 3-year function test, but you were actually pretending to work hard
排序——交换排序
Understanding of Poisson distribution and Poisson process and Erlang distribution and their relations (important theories in queuing theory and operational research)
使用 COCO 数据集训练 YOLOv4-CSP 模型
Servlet、ServletConfig、ServletContext
自定义ViewGroup的知识点总结-持续更新
Methods to improve training speed in deep learning and techniques to reduce video memory (suitable for entry-level trick without too many computing resources)
排序——选择排序
学习《缠解论语》
Collation of basic knowledge of intermediate development of Andrews (for interview)
[atcoder1980] mystious light (mathematical simulation)
排序——归并排序
YUV数据的裁剪与重叠
Uoj 553 [unr 4] caproic acid set [computational geometry (points in circle → points in half plane)]
C. Manipulating History(贪心/哈希/思维/好题)
Opencv for face recognition
Deux diplômés, la Banque a externalisé le travail d'essai pendant plus de quatre mois. Parler de vrais sentiments...