mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-24 09:36:28 +08:00
fix: right-left and left-right inversion for the English version of AVL Tree (#1448)
* Fix right-left and left-right inversion on AVL Binary Tree * Update avl_tree.md * Update avl_tree.md --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
parent
2758e06374
commit
b884d385e3
1 changed files with 4 additions and 4 deletions
|
@ -289,17 +289,17 @@ It can be observed that **the right and left rotation operations are logically s
|
||||||
[file]{avl_tree}-[class]{avl_tree}-[func]{left_rotate}
|
[file]{avl_tree}-[class]{avl_tree}-[func]{left_rotate}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Right-left rotation
|
### Left-right rotation
|
||||||
|
|
||||||
For the unbalanced node 3 shown in the figure below, using either left or right rotation alone cannot restore balance to the subtree. In this case, a "left rotation" needs to be performed on `child` first, followed by a "right rotation" on `node`.
|
For the unbalanced node 3 shown in the figure below, using either left or right rotation alone cannot restore balance to the subtree. In this case, a "left rotation" needs to be performed on `child` first, followed by a "right rotation" on `node`.
|
||||||
|
|
||||||
![Right-left rotation](avl_tree.assets/avltree_left_right_rotate.png)
|
![Left-right rotation](avl_tree.assets/avltree_left_right_rotate.png)
|
||||||
|
|
||||||
### Left-right rotation
|
### Right-left rotation
|
||||||
|
|
||||||
As shown in the figure below, for the mirror case of the above unbalanced binary tree, a "right rotation" needs to be performed on `child` first, followed by a "left rotation" on `node`.
|
As shown in the figure below, for the mirror case of the above unbalanced binary tree, a "right rotation" needs to be performed on `child` first, followed by a "left rotation" on `node`.
|
||||||
|
|
||||||
![Left-right rotation](avl_tree.assets/avltree_right_left_rotate.png)
|
![Right-left rotation](avl_tree.assets/avltree_right_left_rotate.png)
|
||||||
|
|
||||||
### Choice of rotation
|
### Choice of rotation
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue