当前位置:网站首页>Binary tree knowledge
Binary tree knowledge
2022-04-21 09:02:00 【Self cultivation bug】
Binary trees have two main forms : Full binary tree and full binary tree
Full binary tree
If a binary tree has only a degree of 0 The sum is 2, And the degree is 0 A binary tree whose nodes are all on the same layer is a full binary tree

This binary tree is full of binary trees , It can also be said that the depth is k, Yes 2^k-1 A binary tree of nodes
Perfect binary tree
In complete binary tree ,
1. Except that the bottom layer may not be filled ,
2. Every other layer is filled with ,
3. If there is no left subtree in the bottom layer, the following nodes cannot have

If the bottom layer is No h layer , Then the layer contains 1~ 2^(h-1) Nodes
Binary search tree
characteristic :
1. Binary search tree is an ordered tree
2. If his left sub tree is not empty , The value of the left subtree is less than the root node
3. If his right subtree is not empty , The value of the right subtree is greater than the root node

Balanced binary search trees
The absolute value of the height difference between an empty tree or its left and right sub trees does not exceed 1,
And both the left and right subtrees are a balanced binary tree

1.C++ in map、set、multimap,multiset The underlying implementation of is a balanced binary search tree
2.unordered_map、unordered_set,unordered_map、unordered_map The underlying implementation is a hash table
Storage method of binary tree
1. Chain store -----> Linked list
2. Sequential storage ----> Array
The traversal of binary tree
Binary tree mainly has the following two traversal methods :
1. Depth-first traversal : Go deep first , Meet the leaf node and go back
2. Breadth first traversal : Layer by layer to traverse
With these two kinds of traversal, we can expand the following traversal
Depth-first traversal :
1. The first sequence traversal
2. In the sequence traversal
3. Subsequent traversal
Breadth first traversal
1. Level traversal
Here, in front, in the back , In fact, it refers to the traversal order of intermediate nodes , As long as you remember The first, middle and last order refers to the position of the intermediate node, that is, the parent node
The former sequence traversal : Around the middle
In the sequence traversal : Left middle right
After the sequence traversal : Right and left

Experience :
1. When we do binary tree, we often use recursive method to realize depth first traversal , That is to realize the pre -, middle -, and post traversal ,
2. Stack is actually an implementation structure of recursion , In other words, the logic of pre -, middle - and post order traversal can actually be implemented in a non recursive way with the help of the stack
3. The breadth of traversal queue is generally realized by , This is determined by the first in first out characteristic node of the queue , In this way, we can traverse the binary tree layer by layer
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {
}
};
版权声明
本文为[Self cultivation bug]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210856007533.html
边栏推荐
- Flink的api入门案例
- Actual combat analysis of PC wechat robot personal number interface API wechat agrees with friend call
- 年金险安全靠谱吗?收益是多少啊?
- Overview of VoIP technology development and its relationship with outbound call system
- 实战渗透-fofa-dirBrute-代码审计-构造poc-ueditor-解密-过waf-Godzilla
- 渗透实战-无回显Rce-thinkphp5-Getshell
- 【CVPR 2020】PointASNL :Robust Point Clouds Processing using Nonlocal Neural Networks
- Buuctf [geek challenge 2019] havefun
- PyS1:概述
- [appium] use the simulator to realize the business functions of Youdao cloud app - add, search, modify and delete
猜你喜欢

L2-026 small generation (25 points)

Penetration practice - dig a school site vulnerability (APP vulnerability)
What is the product power of the new modern paristi, a joint venture 7-seat SUV with large displacement?

Based on ASP Net online flower shopping management

ZABBIX 5.4 server installation

全网最全谷粒商城笔记_02、简介项目整体效果展示(2022-04-02)

渗透实战-无回显Rce-thinkphp5-Getshell

2022 t elevator repair test questions and online simulation test

2022年上海市安全员C证考试模拟100题及模拟考试

PageRank case Airport
随机推荐
JS -- closure
渗透测试-从公有云到内网漫游RCE-反序列化-frp
Pyinstaller package exe (detailed tutorial)
Penetration practice - dig a school site vulnerability (APP vulnerability)
受控组件与非受控组件
You can remove cached packages by executing ‘yum clean packages‘. Error: GPG check FAILED
kotlin 协程 lanch 详解
postman测试Excel文件导入导出功能
关于印发《湖南省首版次软件产品认定管理办法》的通知
某系统拥有N个进程,总共7个资源,每个进程需要3个资源,问N数量最多为多少不会死锁?(附解析)
Pys1: Overview
Selection of WiFi module for data transmission through industrial control serial port of intelligent gateway of Internet of things
原生与H5混合式开发详解
Enter four integers in descending order
Drafting and Revision: Laplacian Pyramid Network for Fast High-Quality Artistic Style Transfer--T Li
2022 tea artist (primary) examination questions and online simulation examination
[GYCTF2020]Blacklist
A value is trying to be set on a copy of a slice from a DataFrame.
Intranet penetration - proxy penetration - rights lifting - injection - MSF Middleware - domain penetration - log clearing - learning resources
Map Object WeakMap