当前位置:网站首页>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 !
边栏推荐
- [introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
- 3.1 detailed explanation of rtthread serial port device (V1)
- C language circular statement
- STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
- Prime Protocol宣布在Moonbeam上的跨链互连应用程序
- Recommended papers on remote sensing image super-resolution
- math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
- 2.2 STM32 GPIO operation
- C mouse event and keyboard event of C (XXVIII)
- Custom event of C (31)
猜你喜欢
Ks008 SSM based press release system
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
How to modify field constraints (type, default, null, etc.) in a table
Ipv4中的A 、B、C类网络及子网掩码
Overview of super-resolution reconstruction of remote sensing images
2.1 rtthread pin device details
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
MySql数据库root账户无法远程登陆解决办法
Schnuka: 3D vision detection application industry machine vision 3D detection
3.1 detailed explanation of rtthread serial port device (V1)
随机推荐
BUAA计算器(表达式计算-表达式树实现)
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
Mapping between QoE and KQI
RT thread -- FTP of LwIP (2)
Benefits of automated testing
Detailed explanation of serialization and deserialization
Développement d'un module d'élimination des bavardages à clé basé sur la FPGA
User experience index system
Prime Protocol宣布在Moonbeam上的跨链互连应用程序
Determine which week of the month the day is
Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
Use js to complete an LRU cache
Quick sort function in C language -- qsort
Ethernet port &arm & MOS &push-pull open drain &up and down &high and low sides &time domain and frequency domain Fourier
MySQL about self growth
An article will give you a comprehensive understanding of the internal and external components of "computer"
[practice] mathematics in lottery
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
51nod 1130 n factorial length V2 (Stirling approximation)