当前位置:网站首页>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 .
边栏推荐
- NFV基本概述
- c#高級編程-特性篇
- 6. system call
- 怎么写出一份令人惊叹的设计文档?
- How to write an amazing design document?
- RT thread simulator lvgl control: button button event
- redis-6. Redis master-slave replication, cap, Paxos, cluster sharding cluster 01
- 快速排序
- It's called the next generation monitoring system. Let's see how awesome it is
- 【硬记】脏读、不可重复读、幻读场景核心区别
猜你喜欢

First day of learning MySQL Basics

Powerdispatcher reverse generation of Oracle data model

【ViveFocus使用WaveVR插件获取手柄操作事件】

redis-0. Introduction to redis and NiO principle (random talk)

Department store center supply chain management system

微隔离(MSG)

redis-2. Redis string type & bitmap

Xuanwu cloud technology passed the listing hearing: the performance fluctuated significantly, and chenyonghui and other three were the controlling shareholders

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

RT-Thread 模拟器 simulator LVGL控件:button 按钮样式
随机推荐
Interview questions must be asked - Optimization of large table Pagination
June 12, 2022: if there are n*n pieces in an n*n square chessboard, each grid can have exactly one piece. But now some pieces are gathered on a grid, such as 2030100300. The above two-dimensional arra
RT thread simulator lvgl control: switch switch button control
Local file upload FTP or remote directory
How to stop PHP FPM service in php7
Through the function seaborn cubehelix_ Palette build order palette
C # related knowledge points
6. system call
关于c#委托、事件相关问题
Xuanwu cloud technology passed the listing hearing: the performance fluctuated significantly, and chenyonghui and other three were the controlling shareholders
The password does not take effect after redis is set
MySQL query timeout control
Sharp weapon tcpdump
Nfv basic overview
C # Advanced Programming - Feature Section
汇编语言基础:寄存器和寻址方式
Que se passe - t - il si les produits financiers sont nuls pendant plusieurs jours?
微隔离(MSG)
B. I hate 1111 (mnemonic search number theory
Priority analysis of list variables in ansible playbook and how to separate and summarize list variables