当前位置:网站首页>Learning notes of balanced binary tree -- one two pandas
Learning notes of balanced binary tree -- one two pandas
2022-06-13 07:22:00 【One two pandas】
Knowledge record of balanced binary tree .
1. Balance factor . The balance factor of a binary tree is the height difference between the left and right subtrees .HL Is the height of the left binary tree ,HR Is the height of the right binary tree , The equilibrium factor is HL-HR, Note that the balance factor does not take an absolute value .
2. Balanced binary trees . Balanced binary tree means that the absolute value of the height difference between the left and right subtrees of any node in a tree does not exceed 1 The tree of , That is, the absolute value of the balance factor does not exceed one .
Four equilibrium transformations :
When a new node is inserted into a balanced binary tree, it becomes unbalanced , The newly inserted node is Destroy node A, It breaks the balance of a node , Then the destroyed node is called Damaged nodes B . See what the rotation is from Damaged nodes B set out , towards Destroy node A View the path .
The purpose of the transformation is to restore balance , This makes the search binary tree become balanced because of the imbalance after adding new nodes .
The unified strategy is to destroy nodes 、 Damaged nodes 、 The nodes between them calculate the balance factor ( Just count by yourself ), Let the node with the balance factor in the middle be the parent node , The youngest as a left child , The eldest as a right child .
RR The transformation is as follows
When destroying nodes A And damaged nodes B The relationship between is : Destroy node A For the damaged node B Right child's right child , That is to say RR Transformation ( Among them RR It is worth destroying the nodes A And damaged nodes B The relationship between ).
Look down , As shown in the figure below, in BR Node out add a new node , Whether it's BR The left child is still the right child , It's all thought to be RR rotate , because B yes A The right child ,BR yes B The right child , stay BR Insert under , You can put BR It comes down to breaking nodes .
When the following node is unbalanced and its parent node is unbalanced , We adjust the bottom unbalance node , Because the subtree is balanced , The nodes above are balanced .
LL The transformation is as follows 
LR The transformation is as follows
Newly inserted is Jan, cause May Node imbalance ,RL The adjustment is mainly to connect the damaged node to the damaged node and the connecting node between them , Balance refactoring , As shown in the red circle below . Then their children changed accordingly , The child nodes of the original structure from left to right are added to the left and right nodes of the new structure in order , This is to satisfy the condition that the left side is small and the right side is large .

RL The transformation is as follows
The newly added node is Feb, Destroyed Aug Equilibrium state of .
Only make self-study records .
边栏推荐
- 全志V3S环境编译开发流程
- The management practice of leading enterprises has proved that what is the core of sustainable development of enterprises?
- 尝试使用RenderDoc查看UE的Shader代码
- 25个国内外文献数据库
- P6154 wandering (memory search
- 不同系统添加证书
- Priority analysis of list variables in ansible playbook and how to separate and summarize list variables
- What does my financial product mean in clearing?
- Monotone stack top31 of interview must brush algorithm top101
- How to solve the 404 problem
猜你喜欢

First day of learning MySQL Basics

RT thread simulator lvgl control: slider control

Test development programmers, are you still confused? You can't define yourself as a yard farmer

Mui mixed development - when updating the download app, the system status bar displays the download progress

Implementation of fruit mall wholesale platform based on SSM

TCP协议的三次握手过程和四次挥手过程以及为什么要这样? ------一二熊猫

RT-Thread 模拟器 simulator LVGL控件:button 按钮事件

Raspberry school advanced development - "writing of IO port driver code" includes bus address, physical \u virtual address and bcm2835 chip manual knowledge
![[Markov chain Monte Carlo] Markov chain Monte Carlo method sampling prior distribution](/img/8a/e6423168e110a168bc3cc6407628f6.png)
[Markov chain Monte Carlo] Markov chain Monte Carlo method sampling prior distribution

论文笔记: 多标签学习 BP-MLL
随机推荐
RT thread simulator lvgl control: slider control
It's called the next generation monitoring system. Let's see how awesome it is
Why should two judgment expressions in if be written in two lines
P1434 [SHOI2002] 滑雪 (记忆化搜索
Station B crazy God notes
TXT_ File encryption and compression
Functions about Oracle.
Mui mixed development - when updating the download app, the system status bar displays the download progress
One article of quantitative framework backtrader read analyzer
部署RDS服务
全志V3S环境编译开发流程
号称下一代监控系统 来看看它有多牛逼
B. I hate 1111 (mnemonic search number theory
Through the function seaborn cubehelix_ Palette build order palette
Reflection of C # Foundation
RT thread simulator lvgl control: button button event
Local file upload FTP or remote directory
SDN基本概述
redis-4. Redis' message subscription, pipeline, transaction, modules, bloom filter, and cache LRU
汇编语言基础:寄存器和寻址方式