当前位置:网站首页>AVL balanced binary tree and its four rotation modes
AVL balanced binary tree and its four rotation modes
2022-04-21 23:50:00 【Adsh】
1.AVL Balanced binary trees : The absolute value of the height difference between the left subtree and the right subtree of each node in the binary tree is less than or equal to 1.


2. Balance factor = The height of the left subtree - The height of the right subtree .AVL The balance factor of the tree is only -1,0,1.

3. Right rotation LL
Pre rotation feature :
1) node a For unbalanced nodes .
2) node b And nodes c To be on a high path , from a Start with the next two nodes .
3)y1,y2,y3 and y4 Represents a node a, node b, node c A child node or subtree of . It can be for null, Can be a leaf node , It can also be the number of nodes >1 A binary tree of .
4) node b Is the node a Of Left children . node c Is the node b Of Left children .

Features after rotation :
1) node b Become a root node
2) The original root node a Become a node b The right child
3)y3 Become a node a The left child .【 If y3 Not empty , Because before y3 Is the node b The right child , Now the node a Become a node b The right child . because b<y3 Value of root node <a, node a Become a node b Right behind the child , node a No left child . So when y3 Become a node a Behind my left child , Also satisfied b<y3 Value of root node <a.】
4)y1,y2,y4 The relationship with the parent node does not change .

4. Left rotation RR
Pre rotation feature :
1) node a For unbalanced nodes .
2) node b And nodes c To be on a high path , from a Start with the next two nodes .
3)y1,y2,y3 and y4 Represents a node a, node b, node c A child node or subtree of . It can be for null, Can be a leaf node , It can also be the number of nodes >1 A binary tree of .
4) node b Is the node a Of Right children . node c Is the node b Of Right children .

Features after rotation :
1) node b Become a root node
2) The original root node a Become a node b The left child
3)y2 Become a node a The right child .【 If y2 Not empty , Because before y2 Is the node b The left child , Now the node a Become a node b The left child . because a<y2 Value of root node <b, node a Become a node b Behind my left child , node a No right child . So when y2 Become a node a Right behind the child , Also satisfied a<y2 Value of root node <b.】
4)y1,y3,y4 The relationship with the parent node does not change .

5. First left, then right LR
Pre rotation feature :
1) node a For unbalanced nodes .
2) node b And nodes c To be on a high path , from a Start with the next two nodes .
3)y1,y2,y3 and y4 Represents a node a, node b, node c A child node or subtree of . It can be for null, Can be a leaf node , It can also be the number of nodes >1 A binary tree of .
4) node b Is the node a Of Left children . node c Is the node b Of Right children .

step1: Left hand operation

step2: Right hand operation
take step1 The results of right-handed operation

6. Right and then left RL
Pre rotation feature :
1) node a For unbalanced nodes .
2) node b And nodes c To be on a high path , from a Start with the next two nodes .
3)y1,y2,y3 and y4 Represents a node a, node b, node c A child node or subtree of . It can be for null, Can be a leaf node , It can also be the number of nodes >1 A binary tree of .
4) node b Is the node a Of Right children . node c Is the node b Of Left children .

step1: Right hand operation

step2: Left hand operation

版权声明
本文为[Adsh]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211821384470.html
边栏推荐
- leetcode:440. The k-th smallest digit in dictionary order
- The longitude and latitude tables of major cities across the country are kept for future reference
- 找出大于X的第一个质数(DAY 42)
- FreeFileSync的使用教程
- 音视频编解码
- 深度优先和广度优先的区别 笔记
- Centos7 install MySQL using Yum - specify the version
- Judging by JS in IE and edge, you can only enter numbers, letters and date types.
- Click, walk and move of characters in 3D sandbox game
- 【acwing】1125. Cattle travel * * * (Floyd)
猜你喜欢

【acwing】1125. Cattle travel * * * (Floyd)

多表创建视图问题:修改视图数据时报1062

7.3 creating threads

C language topic 1: three digits that can be composed of 1,2,3,4

【acwing】1125. 牛的旅行***(floyd)

DetNet: A Backbone network for Object Detection

Robot OS驱动开发

JDBC概念 在idea里创建JDBC项目步骤

7.5 线程等待终止

Simple and easy to collect navigation website source code
随机推荐
341 Linux connection database
Man machine verification reCAPTCHA V3 complete instructions
SolidWorks hold down Ctrl and drag to copy entities
Wireshark distinguishes between packages
7.9 线程 互斥锁
leetcode:271.字符串的编码与解码
FreeFileSync的使用教程
7.4 thread exit
数据库连接池和Druid的使用
341-Linux 连接数据库
[fundamentals of interface testing] Part V - detailed explanation of interface use case design
5. Network structure and ISP, packet delay, loss, throughput
LeetCode_ 746 climbing stairs with minimum cost
拼多多店铺怎么选择资源位,怎么报名活动,什么活动对店铺利益最大?
leetcode:443. 压缩字符串
通过点击导入的文件或点击组件进入对应的组件页面进行编辑
《数字电子技术基础》3.3 CMOS门电路(下)
存储组 物理量 实体 路径
(Reprint) MySQL read-write separation -- cluster and high concurrency
Difference between breadth first notes and breadth first notes