将以下12个数构建为一个完整的AVL树,且保证每一步都是完整的AVL树:55, 66, 77, 15, 11, 33, 22, 35, 25, 44, 88, 99
时间: 2023-06-24 11:06:53 浏览: 76
以下是构建AVL树的过程:
1. 插入55,得到根节点为55的一棵树:
```
55
```
2. 插入66,得到根节点为55,右子树为66的一棵树:
```
55
\
66
```
3. 插入77,得到根节点为66,左子树为55,右子树为77的一棵树:
```
66
/ \
55 77
```
4. 插入15,得到根节点为66,左子树为AVL树(55,15,11,33,22,35,25)的一棵树,右子树为77的一棵树:
```
66
/ \
(55,15,11,33,22,35,25) 77
```
5. 插入11,得到根节点为55,左子树为AVL树(15,11),右子树为AVL树(33,22,35,25):
```
66
/ \
55 77
/ \
15 (33,22,35,25)
/ \
11 None
```
6. 插入33,得到根节点为55,左子树为AVL树(15,11, None, None, 33,22, None), 右子树为AVL树(77, None, None, None, None, None, None):
```
55
/ \
(15,11, None, None, 33,22, None) 77
```
7. 插入22,得到根节点为33,左子树为AVL树(15,11,None,None,22,None,None),右子树为AVL树(55,None,None,None,None,None,None):
```
55
/ \
(33,15,11,None,22,None,None) 77
```
8. 插入35,得到根节点为33,左子树为AVL树(15,11,None,None,22,None,None),右子树为AVL树(55,None,35,None,None,None,None):
```
55
/ \
(33,15,11,None,22,None,None) 77
\
35
```
9. 插入25,得到根节点为33,左子树为AVL树(15,11,None,None,22,None,None),右子树为AVL树(55,35,None,25,None,None,None):
```
55
/ \
(33,15,11,None,22,None,None) 77
/ \
35 (55,None,25,None,None,None,None)
/
25
```
10. 插入44,得到根节点为33,左子树为AVL树(15,11,None,None,22,None,None),右子树为AVL树(55,35,None,25,44,None,None):
```
55
/ \
(33,15,11,None,22,None,None) 77
/ \
35 (55,44,25,None,None,None,None)
/
25
```
11. 插入88,得到根节点为55,左子树为AVL树(33,15,11,None,22,None,None),右子树为AVL树(77,55,44,35,25,None,88):
```
55
/ \
(33,15,11,None,22,None,None) (77,55,44,35,25,None,88)
```
12. 插入99,得到根节点为55,左子树为AVL树(33,15,11,None,22,None,None),右子树为AVL树(77,55,44,35,25,88,99):
```
55
/ \
(33,15,11,None,22,None,None) (77,55,44,35,25,88,99)
```
因此,最终的AVL树为:
```
55
/ \
(33,15,11,None,22,None,None) (77,55,44,35,25,88,99)
```
阅读全文