Skip to content

Commit 24ec910

Browse files
committed
Update AVLInfo.md
1 parent d23e542 commit 24ec910

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/algorithms/extra-info/AVLInfo.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,44 @@ a:hover{
2121
Geeks for Geeks Link:
2222
<a href="https://www.w3schools.com/dsa/dsa_data_avltrees.php" target="_blank">AVL Tree</a>
2323

24-
Insert detailed information about rotations here.
24+
---------------------------------------------------------------
25+
2526

26-
Rework the following original:
27+
Insert detailed information about rotations here.
2728

2829
# Rotation in AVL trees
2930

31+
When examining any particular subtree of an AVL tree in AIA, the node we use the following **node numbering scheme** which preserves the binary search invariant, that is, node t1 (with value 1) is always to the left of node t2 (value 2), node t2 is always to the left of node t3 (value 3), node t4 is (value 4) always to the right of node t3. Importantly, note also that some of these nodes **may be empty**, and are shown for completeness.
3032

31-
In the diagrams below, t6 is the node where the imbalance is noted.
33+
**Lee -- We should talk about whether this numbering makes things more difficult for a student to understand, or easier.**
34+
35+
A full and completely balanced tree, rooted at node would thus be:
36+
//Comment: need to have empty spaces at the left of this diagram for it to render correctly.
37+
38+
39+
40+
t4
41+
/ \
42+
t2 t6
43+
/ \ / \
44+
t1 t3 t5 t7
3245

33-
As shown in the diagram below, t6 is the node at which the imbalance has been noted, and t2 is its left child. The clockwise rotation to restore balance makes t2 the parent of t6, while t6 is the *right* child of t2. Additionally, since t2 already had t4 as its right child, t4 is moved to become the left child of t6. Note that the BST invariant is preserved: t4, is bigger than t2, and is also smaller than t6. The rotation reduces the distance from the root to t1 (where the new node was added), so the tree is now
46+
The above tree would still be balanced, according to the AVL criterion for balance, if certain nodes or combinations of nodes are empty, for example, t1 or t3 or t5 , or various combinations, such as t1 & t3, or t3 & t5, and so on. The combination t1&t2&t3 would not be allowed, however, as then the tree rooted at t4 would have a left subtree of height 0, and a right subtree with height 2.
47+
48+
49+
Trees with t1 or t3 or t5 empty, or various combinations, such as t1 & t3, or t3 & t5, and so on, empty would still be balanced, according to the AVL criterion of having a difference in height between two subtrees of no more than 1.
50+
51+
52+
53+
In the diagrams below, t6 is the node where the imbalance is noted.
3454

55+
As shown in the diagram below, t6 is the node at which the imbalance has been noted, and t2 is its left child. The clockwise rotation to restore balance makes t2 the parent of t6, while t6 is the *right* child of t2. Additionally, since t2 already had t4 as its right child, t4 is moved to become the left child of t6. Note that theBST invariant is preserved: t4, is bigger than t2, and is also smaller than t6. The rotation reduces the distance from the root to t1 (where the new node was added), so the tree is no
3556

3657

3758

3859

3960

40-
, as explained in the diagram The 6 and 4 nodes and the edge between them rotate clockwise, and
61+
, as explained in the diagram The 6 and 4 nodes and the edge between them rotate cloc kwise, and
4162
the 5 node changes parents from 4 to 6. This reduces the distance from
4263
the root to the 1 (where the new node was added), restoring the balance
4364
(the distance to the node rooted at 7 is increased but this does not

0 commit comments

Comments
 (0)