当前位置:网站首页>Binary tree concept
Binary tree concept
2022-07-27 18:23:00 【zh_ Tnis】
1. The definition of a tree .
A tree is formed by connecting nodes , The next node connected by each node cannot be connected to each other , Otherwise, the graph is not a tree .
2. Classification of tree nodes .
The root node : The first node of the tree .
degree : Connect 2 Nodes , It's Duwei 2, Connect 1 Nodes , It's Duwei 1, Do not connect nodes , It's Duwei 0.
Leaf nodes : Nodes that are not connected to nodes are called leaf nodes .
3. Tree hierarchy .
The maximum depth of a node in a tree .
4. Brief description of tree graph ( Example of binary tree ).

5. The definition of binary tree .
Each node has at most two subtrees , The order of left and right subtrees .
6. Five basic forms of binary trees .
① Empty binary tree .
② Only one root node .
③ Only the left sub tree .
④ Only the right subtree .
⑤ There are both left and right subtrees .

7. Special case of binary tree .
① Oblique tree : Equivalent to left subtree and right subtree
② Full binary tree : Maximum depth — The lowest depth is equal to 0, And the nonexistence degree is 1 The situation of .
③ Balanced subtree : Maximum depth — The minimum depth is less than or equal to 1 The are .
④ Perfect binary tree :1、 Leaf nodes have only the last two layers .2、 The lowest leaves can only be arranged from left to right .3、 Last but not least 2 layer , If there are leaf nodes , It must be right continuous .4、 If the node degree is 1, It must be connected to the left node .5、 Same node arrangement , The depth of a complete binary tree is the smallest .

8. Properties of binary trees .
① At most per floor 2^(i-1) Nodes .
② Depth is k There are at most 2^k-1 Nodes .
③ For any binary tree , Degree is 0 The node of ( total N0) Yes, the degree is 2 The node of ( total N2) Of :N0=N2-1.
④ have n The depth of the binary tree of nodes is |log2^n|+1, Such as log2^15+1=4.
⑤ For one n A binary tree of nodes , After numbering
1、 If i=1, Then there is no connection to his previous node . if i>1, Then the node connecting it is |i/2|, Such as 3/2=1.
2、 If 2i>n, The node i No left child tree , Otherwise, the left subtree is numbered 2i.
3、 If 2i+1>n, The node i No right subtree , Otherwise, the right subtree is numbered 2i+1.
9. Traversal of binary tree .
DFS Depth-first traversal : abbreviation Shenyou .
BFS Breadth first traversal : abbreviation Guangyou .
The following figure is a binary tree for explanation and analysis .

D The node value L The left subtree value of this node R The right subtree value of this node
Shenyou ①—— The former sequence traversal DLR: Output ABDGHJCEIF
analysis :A Advanced stack , After coming out , Stack right and left , Put the right and left on the stack after each one , Until it is finished, it is the element output of the preorder traversal .
Shenyou ②—— In the sequence traversal LDR: Output GDJHBAEICF
analysis :A Start turning left All Put nodes on the stack , Each one will be on the left side of the right subtree All Put it on the stack , If there is no right, it will go out .
Shenyou ③—— After the sequence traversal LRD: Output GJHDBIEFCA
analysis :A Begin to Put all the left ones on the stack , At the last moment Judge whether there is a node on the right , Some words Put the left side of the right subtree into the stack one by one , until No more Just one , After going out , Right again There are no nodes in the right subtree of the judgment that is about to be given , Existence continues to stack all the left and right , Until all elements are output .
Guangyou —— Sequence traversal ( queue ): Output ABCDEFGHIJ
analysis :A advanced , After coming out, put it in the left and right order , Put each one in the left and right order , Until completion .
边栏推荐
- 展锐鲜苗:赋能全场景应用,海量数据需要AI与IoT融合
- 深度学习:GCN案例
- Deep recognition: thesis reading_ 2s-agcn cvpr2019 (two stream adaptive graph convolution network based on skeleton action recognition)
- Collection! 0 basic open source data visualization platform flyfish large screen development guide
- 同心向前,Google Play 十周年啦!
- 美团二面:为什么Redis会有哨兵?
- 深度学习:STGCN学习笔记
- 宣布收购文晔30%股份,大联大意欲何为?
- @Scheduled and quartz
- Hackers use lasers to attack, and voice assistants can be activated from a distance of 100 meters
猜你喜欢

On recommend mechanism in distributed training

Deep recognition: thesis reading_ 2s-agcn cvpr2019 (two stream adaptive graph convolution network based on skeleton action recognition)

技术分享| 快对讲综合调度系统

Deep learning: gat

Error launching IDEA

浅论分布式训练中的recompute机制

Salesforce runs all test classes and gets coverage reports
![[learning notes] advanced version of MySQL database - index optimization, slow query, locking mechanism, etc](/img/7a/7497a73b435c3ed4fa0f3a3e908298.jpg)
[learning notes] advanced version of MySQL database - index optimization, slow query, locking mechanism, etc

深度学习:GCN(图卷积神经网络)理论学习总结

Deep learning: GCN (graph convolution neural network) theory learning summary
随机推荐
Error launching IDEA
[MIT 6.S081] Lec 5: Calling conventions and stack frames RISC-V 笔记
[learning notes] classification of locks in the database
1542. Find the longest super substring hash + state compression
荣耀、小米发双十一战报:都称自己是冠军
给程序界面增加音乐,加载背景照片。
被“赶出”比特大陆之后,詹克团首度发声:将通过法律途径尽快回归!
联发科首款5G SoC来了!A77+G77+APU3.0,11月26日正式发布!
Super practical! After reading the kubernetes study notes hidden by Alibaba P9, call NB directly
CFA exam registration instructions
浅论分布式训练中的recompute机制
记一次 .NET 某智慧物流 WCS系统 CPU 爆高分析
[MIT 6.S081] Lab 9: file system
Salesforce Dynamic Forms
深度学习:GAN优化方法-DCGAN案例
深度学习-论文阅读:动作结构性图卷积网络AS-GCN
Bubble sorting in JS
SQL Server连接到服务器无效的解决办法
Golang waits for a group of goroutines to complete with the return value (2)
Three consecutive high-frequency interview questions of redis online celebrity: cache penetration? Cache breakdown? Cache avalanche?