当前位置:网站首页>Basic knowledge of binary tree, BFC, DFS
Basic knowledge of binary tree, BFC, DFS
2022-07-06 03:57:00 【Pupu pupu】
Author: intellectuals
Computer science
Controllable things Heavy and calm Uncontrollable things Optimistic face
[email protected]
️
️ ️ ️
————————————————
Copyright notice : This paper is about CSDN Blogger 「 Pu Shangqing sky 」 The original article of
List of articles
Knowledge point
Binary tree
- If specified The number of node layers of the root is 1, Then the... Of a non empty binary tree i There is a maximum of 2 Of i-1 Power (i > 0) Nodes
- If the root node depth of the binary tree is specified as 1, Then the depth is K Two fork tree Maximum number of nodes 2 Of k Power -1
- For any binary tree , If the number of leaf nodes is n0, Degree is 2 The number of non leaf nodes is n2, be n0=n2+1
- have n The depth of a complete binary tree of nodes k be equal to log With 2 Bottom n+1, Rounding up
- Subscript relation
If the parent node is known parent The subscript
Left the child :leftChild = 2parent+1
The right child :rightChild = 2parent +2
If the child is known child node
parent = (child-1)/2

Binary tree traversal
DFS: Depth-first traversal - Stack
The former sequence traversal :
traversal order : recursive
Put the root node in front
1. First , Handle The root node
2. next , Complete traversal of the root The left subtree
3. Last , Complete traversal of the root Right subtree 
① We are from Root node Start ,
namely : A{ } { }
② Because we are traversing first The left subtree
therefore , A { B{}{} } { }
A { B{ D{}{} }{} } { }
A { B{ D{}{undefinedG} }{} } { }
③ Last traversal Right subtree :
A { B{ D{}{undefinedG} }{} } { C{}{} }
A { B{ D{}{undefinedG} }{} } { C{undefinedE}{} }
A { B{ D{}{undefinedG} }{} } { C{undefinedE}{ F{}{} } }
A { B{ D{}{undefinedG} }{} } { C{undefinedE}{ F{undefinedH}{} } }
So we get the result of our first order traversal :
A B D G C E F H
In the sequence traversal
- traversal order :( recursive )
1. First traverse the whole tree The left subtree
2. Intermediate treatment The root node
3. Then traverse the whole tree Right subtree
Let's go through The left subtree , The traversal method is In the sequence traversal
{ {}B{} } A { }
{ { {}D{} }B{} } A { }
{ { {}D{undefinedG} }B{} } A { }
Let's go over Right subtree , The traversal method is still In the sequence traversal
{ { {}D{undefinedG} }B{} } A { {}C{} }
{ { {}D{undefinedG} }B{} } A { {E}C{} }
{ { {}D{undefinedG} }B{} } A { {undefinedE}C{ {}F{} } }
{ { {}D{undefinedG} }B{} } A { {undefinedE}C{ {H}F{} } }
So we get our In the sequence traversal The result :
D G B A E C H F
After the sequence traversal
- traversal order ( recursive )
1. First traversal The left subtree
2. Re traversal Right subtree
3. Finally deal with The root node
Let's go through The left subtree , The traversal method is After the sequence traversal :
{ {}{}B } { }A
{ { {}{}D }{}B } { }A
{ { {}{undefinedG}D }{}B } { }A
Let's go over Right subtree , The traversal method is still After the sequence traversal
{ { {}{undefinedG}D }{}B } { }A
{ { {}{undefinedG}D }{}B } { {}{}C }A
{ { {}{undefinedG}D }{}B } { {undefinedE}{}C }A
{ { {}{undefinedG}D }{}B } { {undefinedE}{ {}{}F }C }A
{ { {}{undefinedG}D }{}B } { {undefinedE}{ {undefinedH}F}{}C }A
So we get our After the sequence traversal The result :
G D B E H F C A
BFC: Breadth first traversal
Sequence traversal ( queue )
purpose : Determine whether it is a complete binary tree
- From top to bottom , Traverse the binary tree from left to right

Code order
1. Start-up phase : Put the root node in the queue

2. Turn on the cycle , Until the queue is empty (isEmpty)
- Take the first node from the queue
- Sequence traversal passes through this node ( Print )
- Put the left of the node / Put the right child node into the queue

Praise first and then watch , Develop habits !!!^ _ ^
Update your knowledge every day !!!
It's not easy to code words , Everyone's support is my driving force to stick to it . Don't forget after you like Focus on I oh !
边栏推荐
- 【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
- Serial port-rs232-rs485-ttl
- 3.2 detailed explanation of rtthread serial port device (V2)
- TCP/IP协议里面的网关地址和ip地址有什么区别?
- Python book learning notes - Chapter 09 section 01 create and use classes
- Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
- C#(三十)之C#comboBox ListView treeView
- AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
- How to standardize the deployment of automated testing?
- mysql从一个连续时间段的表中读取缺少数据
猜你喜欢

RT thread -- FTP of LwIP (2)

MySQL master-slave replication

ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制

3.1 detailed explanation of rtthread serial port device (V1)

多项目编程极简用例

Detailed explanation of serialization and deserialization

Data analysis Seaborn visualization (for personal use)

The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched

C form application of C (27)

【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
随机推荐
Maxay paper latex template description
Blue Bridge Cup - day of week
Multi project programming minimalist use case
C#(三十)之C#comboBox ListView treeView
有条件地 [JsonIgnore]
Microkernel structure understanding
Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
JS Vanke banner rotation chart JS special effect
Benefits of automated testing
Mathematical modeling regression analysis relationship between variables
Cubemx transplantation punctual atom LCD display routine
Thread sleep, thread sleep application scenarios
C mouse event and keyboard event of C (XXVIII)
Image super resolution using deep revolutionary networks (srcnn) interpretation and Implementation
Facebook等大厂超十亿用户数据遭泄露,早该关注DID了
[prediction model] difference method model
JVM的手术刀式剖析——一文带你窥探JVM的秘密
[meisai] meisai thesis reference template
BUAA计算器(表达式计算-表达式树实现)
【按键消抖】基于FPGA的按键消抖模块开发