Skip to content

Commit 2f8f348

Browse files
Update readme;
1 parent 5cc12cd commit 2f8f348

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

AVL Tree/README.markdown

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,21 @@ If after an insertion or deletion the balance factor becomes greater than 1, the
4545
## Rotations
4646
Each tree node keeps track of its current balance factor in a variable. After inserting a new node, we need to update the balance factor of its parent node. If that balance factor becomes greater than 1, we "rotate" part of that tree to restore the balance.
4747

48-
Example of balancing the unbalanced tree using *Right* (clockwise direction) rotation :
49-
![Rotation](Images/Rotation.jpg)
48+
Example of balancing the unbalanced tree using *Right* (clockwise direction) rotation:
49+
![Rotation0](Images/RotationStep0.jpg)
5050

51-
Let's dig into rotation algorithm in detail using the terminology:
51+
For the rotation we're using the terminology:
5252
* *Root* - the parent not of the subtrees that will be rotated;
5353
* *Pivot* - the node that will become parent (basically will be on the *Root*'s position) after rotation;
5454
* *RotationSubtree* - subtree of the *Pivot* upon the side of rotation
5555
* *OppositeSubtree* - subtree of the *Pivot* opposite the side of rotation
5656

57+
![Rotation1](Images/RotationStep1.jpg) ![Rotation2](Images/RotationStep2.jpg) ![Rotation3](Images/RotationStep3.jpg)
58+
5759
The steps of rotation on the example image could be described by following:
58-
* Select the *Pivot* as `D` and hence the *Root* as `F`;
59-
* Assign the *RotationSubtree* as a new *OppositeSubtree* for the *Root*;
60-
* Assign the *Root* as a new *RotationSubtree* for the *Pivot*;
61-
* Check the final result
60+
1. Assign the *RotationSubtree* as a new *OppositeSubtree* for the *Root*;
61+
2. Assign the *Root* as a new *RotationSubtree* for the *Pivot*;
62+
3. Check the final result
6263

6364
In pseudocode the algorithm above could be written as follows:
6465
```

0 commit comments

Comments
 (0)