当前位置:网站首页>Perfect binary tree, complete binary tree, perfect binary tree
Perfect binary tree, complete binary tree, perfect binary tree
2022-06-29 09:58:00 【Water like ice】
1、 Binary tree (Binary Tree)
1.1 What is a binary tree (Binary Tree)
Each node has at most two subtrees ( That is, there is no greater than in the binary tree 2 The node of ), also , The subtree of a binary tree has left and right branches , The order cannot be reversed arbitrarily .
1.2 Properties of binary trees
- If the level of binary tree is from 0 Start , It's in the second place of the binary tree i Layer up to have a 2^i Nodes (i>=0).
- The height is k There are at most 2^(k+1) - 1 Nodes (k>=-1). ( The height of the empty tree is -1)
- Any binary tree , If its leaf node ( Degree is 0) The number of m, Degree is 2 The node number of is n, be m = n + 1.
2、 Perfect binary tree
One depth is k(>=-1) And there are 2^(k+1) - 1 A binary tree with two nodes is called Perfect binary tree
let me put it another way : The trees are full , It's still binary
The graph looks like this : 
3、 Perfect binary tree (Complete)
The complete binary tree satisfies the perfect binary tree from the root node to the penultimate layer , The last layer can not be completely filled , Its leaf nodes are aligned to the left
The figure below shows No A tree is completely (Complete) Binary tree 
If you will number 11(K) Node number 6(E) The position of the left son of moves to the number 5(E) The right son of , It becomes a complete tree (Complete) Binary tree .
- Actually , Understand completely (Complete) A binary tree can be constructed by means of a stack (stack) Thought . for example , Make the first picture perfect (Perfect) All nodes of the binary tree are numbered 1, 2, 3, …, 15 Stack in turn (push). that , Every time the stack goes out (pop) After the operation , In the stack Saved node set Corresponding to the graph, there is a complete tree (Complete) Binary tree
4、 Complete binary tree
The degree of all non leaf nodes is 2
let me put it another way : As long as you have children , You must have Two children .
Reference blog :
Perfect binary tree , Complete binary tree and perfect binary tree
example :
One has 767 A complete binary tree of nodes , The number of leaf nodes is ____
A . 383
B . 384
C . 385
D . 386
n = n2+n1+no
n0 = n2 + 1
We can get the equation :n0= (768-n1) / 2, Because the node of complete binary number is 1 The number of is not 1 Otherwise 0, So choose B.
- n: Total nodes
- n2: Degree is 2 Of nodes
- n1: Degree is 1 Node book of
- n0: Degree is 0 Number of nodes
边栏推荐
- 共用体Union
- 数据库常见面试题(附答案)
- Matlab tips (21) matrix analysis -- partial least squares regression
- Middle order traversal of Li Kou 94 binary tree
- Custom MVC framework implementation
- Introduction to intranet penetration tool FRP
- 证券账号开户安全吗?是靠谱的吗?
- [noi Simulation Competition] add points for noi (heavy chain dissection, line segment tree)
- Generic paging framework
- Wechat applet realizes store function
猜你喜欢

2020-09-29 非商品模板化代码层次 rapidjson库

转载 :判断对象是否具有属性的5种方法

基於PyQt5和Qt Designer的簡易加法計算器的制作

Hystrix熔断器:服务熔断与服务降级

Closed door cultivation (24) shallow understanding of cross domain problems

A 3D Dual Path U-Net of Cancer Segmentation Based on MRI

装饰器模式的应用,包装ServletRequest,增加addParameter方法

UE4 compile a single file (VS and editor start respectively)

通用分页框架

Automatic 3D Detection and Segmentation of Head and Neck Cancer from MRI Data.
随机推荐
C语言实现一种创建易管理易维护线程的方法
Data warehouse: layered architecture of Finance / banking
cenos7下搭建LAMP环境
安装Anaconda后启动JupyterLab需要输入密码
Set up lamp environment under cenos7
FreeRTOS(八)——时间管理
Wechat applet rewrites the page function to realize global logging
Slider validation code
微信小程序实现数据侦听器watch,包含销毁watch和子属性的watch
数据库常见面试题(附答案)
Cloud management platform: openstack architecture design and detailed interpretation
Data governance: data standard management (Part III)
kdevelop新建工程
ImageView picture fill problem
JS obtain mobile phone model and system version
Making of simple addition calculator based on pyqt5 and QT Designer
CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION
C # judge whether the array contains any items of another array
KiCad学习笔记--快捷键
Gmail:如何快速将邮件全部已读