当前位置:网站首页>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 !
边栏推荐
- Determine which week of the month the day is
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
- 简述C语言中的符号和链接库
- MySQL 中的数据类型介绍
- Cf464e the classic problem [shortest path, chairman tree]
- C#(二十七)之C#窗体应用
- JVM的手术刀式剖析——一文带你窥探JVM的秘密
- Pytoch foundation - (2) mathematical operation of tensor
- C#(三十)之C#comboBox ListView treeView
猜你喜欢

BUAA magpie nesting

Exchange bottles (graph theory + thinking)
![[meisai] meisai thesis reference template](/img/14/b39e1db0b5b35702508068e028ee5a.jpg)
[meisai] meisai thesis reference template

No qualifying bean of type ‘......‘ available

ESP32_ FreeRTOS_ Arduino_ 1_ Create task

STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储

2.1 rtthread pin device details

C#(二十七)之C#窗体应用

Viewing and verifying backup sets using dmrman

Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
随机推荐
2. GPIO related operations
Thread sleep, thread sleep application scenarios
ESP32_ FreeRTOS_ Arduino_ 1_ Create task
On Data Mining
math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
Mapping between QoE and KQI
[meisai] meisai thesis reference template
How to modify field constraints (type, default, null, etc.) in a table
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
C#(二十七)之C#窗体应用
简易博客系统
Why do you want to start pointer compression?
3.1 detailed explanation of rtthread serial port device (V1)
Flask learning and project practice 9: WTF form verification
RT thread -- FTP of LwIP (2)
[001] [stm32] how to download STM32 original factory data
[optimization model] Monte Carlo method of optimization calculation
KS008基于SSM的新闻发布系统
Blue Bridge Cup - Castle formula
math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi