当前位置:网站首页>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 !
边栏推荐
- Align items and align content in flex layout
- Multi project programming minimalist use case
- mysql关于自增长增长问题
- [analysis of variance] single factor analysis and multi factor analysis
- Mathematical modeling regression analysis relationship between variables
- Pytoch foundation - (1) initialization of tensors
- 3分钟带你了解微信小程序开发
- 判断当天是当月的第几周
- Security xxE vulnerability recurrence (XXe Lab)
- Oracle ORA error message
猜你喜欢
Schnuka: 3D vision detection application industry machine vision 3D detection
Viewing and verifying backup sets using dmrman
【FPGA教程案例11】基于vivado核的除法器设计与实现
C language -- structs, unions, enumerations, and custom types
[analysis of variance] single factor analysis and multi factor analysis
User experience index system
mysql关于自增长增长问题
Simple blog system
JVM的手术刀式剖析——一文带你窥探JVM的秘密
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
随机推荐
[prediction model] difference method model
2.1 rtthread pin device details
《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
[optimization model] Monte Carlo method of optimization calculation
[FPGA tutorial case 11] design and implementation of divider based on vivado core
Interface idempotency
Maxay paper latex template description
阿里测试师用UI自动化测试实现元素定位
1. New project
math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
[matlab] - draw a five-star red flag
Simple blog system
math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
WPF效果第一百九十一篇之框选ListBox
在字节做测试5年,7月无情被辞,想给划水的兄弟提个醒
Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
3.2 detailed explanation of rtthread serial port device (V2)
Cf603e pastoral oddities [CDQ divide and conquer, revocable and search set]
[Massey] Massey font format and typesetting requirements