translation: Add the initial translation for the tree chapter (#1208)

* Add the initial translation for the tree chapter

* Add intial translation of array_representation_of_tree.md

* Fix the code link of avl_tree
This commit is contained in:
Yudong Jin
2024-04-02 17:02:03 +08:00
committed by GitHub
parent b3f100aff1
commit 3b797d56af
60 changed files with 1476 additions and 16 deletions

View File

@ -226,7 +226,7 @@ AVL 树既是二叉搜索树,也是平衡二叉树,同时满足这两类二
“节点高度”是指从该节点到它的最远叶节点的距离,即所经过的“边”的数量。需要特别注意的是,叶节点的高度为 $0$ ,而空节点的高度为 $-1$ 。我们将创建两个工具函数,分别用于获取和更新节点的高度:
```src
[file]{avl_tree}-[class]{a_v_l_tree}-[func]{update_height}
[file]{avl_tree}-[class]{avl_tree}-[func]{update_height}
```
### 节点平衡因子
@ -234,7 +234,7 @@ AVL 树既是二叉搜索树,也是平衡二叉树,同时满足这两类二
节点的「平衡因子 balance factor」定义为节点左子树的高度减去右子树的高度同时规定空节点的平衡因子为 $0$ 。我们同样将获取节点平衡因子的功能封装成函数,方便后续使用:
```src
[file]{avl_tree}-[class]{a_v_l_tree}-[func]{balance_factor}
[file]{avl_tree}-[class]{avl_tree}-[func]{balance_factor}
```
!!! note
@ -270,7 +270,7 @@ AVL 树的特点在于“旋转”操作,它能够在不影响二叉树的中
“向右旋转”是一种形象化的说法,实际上需要通过修改节点指针来实现,代码如下所示:
```src
[file]{avl_tree}-[class]{a_v_l_tree}-[func]{right_rotate}
[file]{avl_tree}-[class]{avl_tree}-[func]{right_rotate}
```
### 左旋
@ -286,7 +286,7 @@ AVL 树的特点在于“旋转”操作,它能够在不影响二叉树的中
可以观察到,**右旋和左旋操作在逻辑上是镜像对称的,它们分别解决的两种失衡情况也是对称的**。基于对称性,我们只需将右旋的实现代码中的所有的 `left` 替换为 `right` ,将所有的 `right` 替换为 `left` ,即可得到左旋的实现代码:
```src
[file]{avl_tree}-[class]{a_v_l_tree}-[func]{left_rotate}
[file]{avl_tree}-[class]{avl_tree}-[func]{left_rotate}
```
### 先左旋后右旋
@ -321,7 +321,7 @@ AVL 树的特点在于“旋转”操作,它能够在不影响二叉树的中
为了便于使用,我们将旋转操作封装成一个函数。**有了这个函数,我们就能对各种失衡情况进行旋转,使失衡节点重新恢复平衡**。代码如下所示:
```src
[file]{avl_tree}-[class]{a_v_l_tree}-[func]{rotate}
[file]{avl_tree}-[class]{avl_tree}-[func]{rotate}
```
## AVL 树常用操作
@ -331,7 +331,7 @@ AVL 树的特点在于“旋转”操作,它能够在不影响二叉树的中
AVL 树的节点插入操作与二叉搜索树在主体上类似。唯一的区别在于,在 AVL 树中插入节点后,从该节点到根节点的路径上可能会出现一系列失衡节点。因此,**我们需要从这个节点开始,自底向上执行旋转操作,使所有失衡节点恢复平衡**。代码如下所示:
```src
[file]{avl_tree}-[class]{a_v_l_tree}-[func]{insert_helper}
[file]{avl_tree}-[class]{avl_tree}-[func]{insert_helper}
```
### 删除节点
@ -339,7 +339,7 @@ AVL 树的节点插入操作与二叉搜索树在主体上类似。唯一的区
类似地,在二叉搜索树的删除节点方法的基础上,需要从底至顶执行旋转操作,使所有失衡节点恢复平衡。代码如下所示:
```src
[file]{avl_tree}-[class]{a_v_l_tree}-[func]{remove_helper}
[file]{avl_tree}-[class]{avl_tree}-[func]{remove_helper}
```
### 查找节点