Skip to content

Commit

Permalink
Fix avl_tree.md
Browse files Browse the repository at this point in the history
  • Loading branch information
krahets committed Feb 5, 2023
1 parent e3f0151 commit 6778557
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ site/
scripts/
docs/overrides/

docs/src
src/
19 changes: 8 additions & 11 deletions docs/chapter_tree/avl_tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,20 +411,16 @@ AVL 树的独特之处在于「旋转 Rotation」的操作,其可 **在不影
如下图所示(结点下方为「平衡因子」),从底至顶看,二叉树中首个失衡结点是 **结点 3**。我们聚焦在以该失衡结点为根结点的子树上,将该结点记为 `node` ,将其左子节点记为 `child` ,执行「右旋」操作。完成右旋后,该子树已经恢复平衡,并且仍然为二叉搜索树。

=== "Step 1"

![right_rotate_step1](avl_tree.assets/right_rotate_step1.png)
![right_rotate_step1](avl_tree.assets/right_rotate_step1.png)

=== "Step 2"

![right_rotate_step2](avl_tree.assets/right_rotate_step2.png)
![right_rotate_step2](avl_tree.assets/right_rotate_step2.png)

=== "Step 3"

![right_rotate_step3](avl_tree.assets/right_rotate_step3.png)
![right_rotate_step3](avl_tree.assets/right_rotate_step3.png)

=== "Step 4"

![right_rotate_step4](avl_tree.assets/right_rotate_step4.png)
![right_rotate_step4](avl_tree.assets/right_rotate_step4.png)

进而,如果结点 `child` 本身有右子结点(记为 `grandChild` ),则需要在「右旋」中添加一步:将 `grandChild` 作为 `node` 的左子结点。

Expand Down Expand Up @@ -1580,8 +1576,9 @@ AVL 树的独特之处在于「旋转 Rotation」的操作,其可 **在不影

## 7.4.4. AVL 树典型应用

- 组织存储大型数据,适用于高频查找、低频增删场景;
- 用于建立数据库中的索引系统;
- 组织存储大型数据,适用于高频查找、低频增删场景;
- 用于建立数据库中的索引系统;

!!! question "为什么红黑树比 AVL 树更受欢迎?"
红黑树的平衡条件相对宽松,因此在红黑树中插入与删除结点所需的旋转操作相对更少,结点增删操作相比 AVL 树的效率更高。

红黑树的平衡条件相对宽松,因此在红黑树中插入与删除结点所需的旋转操作相对更少,结点增删操作相比 AVL 树的效率更高。

0 comments on commit 6778557

Please sign in to comment.