Skip to content

Commit 14f0c98

Browse files
authored
Update AVLExp.md
Intermediate save to view
1 parent c0c5e1a commit 14f0c98

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/algorithms/explanations/AVLExp.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# AVL Trees
22

3-
AVL trees are **self-balancing** binary search trees.
3+
An AVL tree is **self-balancing** binary search tree.
4+
45
Because the AVL tree is always balanced, search will be *O(log n)*,
5-
no matter what the order of the input data.
6+
no matter what the order of the input data.
67

78
### Binary Search Trees
89

@@ -23,21 +24,21 @@ for each
2324

2425
### AVL tree balancing
2526

26-
The AVL tree preserves the balance of the tree by checking after every insertion to detect
27+
The AVL tree preserves the balance of the tree by (1) checking after every insertion to detect
2728
when the tree has become unbalanced
28-
and performing one or more rotation operations to restore balance when necessary.
29+
and (2) performing one or more rotation operations to restore balance when necessary.
2930
Unbalanced is defined as a difference of more than `1` between the heights of the left and right subtrees.
3031

31-
(Here **maybe insert small pictures, thumbnails?** to show -- unbalanced at gp of new node,
32+
(Here **MAYBE insert small pictures, thumbnails?** to show -- unbalanced at gp of new node,
3233
and also balanced at gp but unblanaced at ggp.)
3334

34-
A (temporarily) unbalanced tree takes on one of two configurations, *zig-zag* or *zig-zig*, and the
35-
sequence of rotations depends on the configuration around the node where the unbalance is detected.
35+
A temporarily unbalanced AVL tree takes on one of two configurations, *zig-zag* or *zig-zig*. The
36+
sequence of rotations depends on the configuration around the node where the imbalance is detected.
3637

3738
### Zig-zig case
3839

39-
In the *zig-zig* case, the child and grandchild nodes of the unbalanced are either both
40-
left subtrees or both right subtrees.
40+
The *zig-zig* configuration has two mirror-image cases: the child and grandchild nodes or subtrees of the unbalanced node are
41+
either (1) both left subtrees or (2) both right subtrees.
4142

4243

4344
## The left-left case
@@ -46,9 +47,11 @@ If the new key was added to the left child of the left child (the
4647
*left-left* case), the balance can be
4748
restored with a single _**Right Rotation**_ operation.
4849

49-
**This is not quite correct, as I think unbalance can occur at the great-great grandparent
50-
without occuring at the parent**
50+
Note that the imbalance may be located further up the tree than the immediate grandparent of the newly inserted node:
5151

52+
**Insert very small diagrams showing (a) imbalance of the grandparent-parent and (b) imbalance of the great grandparent**
53+
*Note that all diagrams should hae nodes in BST order, and where the subtrees are not necessarily single nodes, represent them as subtree-triangles*
54+
*Have arrow showing which node is not in blanace*
5255

5356

5457
, as explained in the diagram
@@ -59,7 +62,7 @@ the root to the 1 (where the new node was added), restoring the balance
5962
cause the AVL tree balance condition to be violated). Right rotation is
6063
done by calling rightRotate(t6), where t6 is the tree rooted at 6.
6164

62-
![](images/AVL/AVL-left-left.jpg) Picture courtesy of Greek for Geeks
65+
![](images/AVL/AVL-left-left.jpg) This picture is from Greek for Geeks, and is only a placeholder to show proof of concept inserting diagrams, and to check things like size and cropping.
6366

6467

6568

0 commit comments

Comments
 (0)