Skip to content

Commit a334d40

Browse files
ClémentClément
authored andcommitted
Adding clarification on RotateleftChild.
1 parent bbe0e85 commit a334d40

6 files changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
%%% An AVL tree
2+
3+
A((12))-->B((10))
4+
A-->C((13))
5+
B-->D((9))
6+
B~~~H1:::hidden
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
%%% An AVL tree before rebalancing using RotateleftChild on a subtree
2+
3+
A((12))-->B((10))
4+
A-->C((13))
5+
B-->D((9))
6+
D-->E((8))
7+
B~~~H1:::hidden
8+
D~~~H2:::hidden
9+
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
%%% An AVL tree after rebalancing using RotateleftChild on a subtree
2+
3+
A((12))-->B((9))
4+
A-->C((13))
5+
B-->D((8))
6+
B-->E((10))
7+
E-->F((null))
8+
E~~~H1:::hidden
9+
10+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
%%% An AVL tree
2+
3+
A((10))-->B((9))
4+
A~~~H1:::hidden
5+
B~~~H2:::hidden
6+
B-->E((null))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
%%% An AVL tree
2+
3+
A((9))~~~H1:::hidden
4+
A-->B((10))
5+
B-->C((null))
6+
B~~~H2:::hidden

source/lectures/data/AVLtrees.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,31 @@ It is also possible to compute the height of nodes "on the fly" instead of stori
6767
- inheriting from the `BTree` class [explored previously](./lectures/data/trees),
6868
- adding an `IBTree` class that allows you to explore the re-balancing methods more freely,
6969
- containing some examples showcasing how re-balancing works.
70+
71+
### Additional Example
72+
73+
Consider the following example:
74+
75+
!include diag/gra/avltree_example_1.md
76+
77+
After inserting 8, the tree would become un-balanced and require to call `RotateleftChild`:
78+
79+
!include diag/gra/avltree_example_2.md
80+
81+
The detail to note here is that `RotateleftChild` is called with
82+
83+
- `nodeTop` being 10,
84+
- `nodeLeft` being 9,
85+
- and `nodeLeft.Right` being `null`,
86+
87+
aka, going from
88+
89+
!include diag/gra/avltree_subtree_1.md
90+
91+
to
92+
93+
!include diag/gra/avltree_subtree_2.md
94+
95+
and since the node with value 8 remains the right child of the node with value 9, we obtain (marking explicitely the `null` node that was manipulated):
96+
97+
!include diag/gra/avltree_example_3.md

0 commit comments

Comments
 (0)