|
| 1 | +# AVL Tree |
| 2 | + |
| 3 | +In computer science, an AVL tree (named after inventors |
| 4 | +Adelson-Velsky and Landis) is a self-balancing binary search |
| 5 | +tree. It was the first such data structure to be invented. |
| 6 | +In an AVL tree, the heights of the two child subtrees of any |
| 7 | +node differ by at most one; if at any time they differ by |
| 8 | +more than one, rebalancing is done to restore this property. |
| 9 | +Lookup, insertion, and deletion all take `O(log n)` time in |
| 10 | +both the average and worst cases, where n is the number of |
| 11 | +nodes in the tree prior to the operation. Insertions and |
| 12 | +deletions may require the tree to be rebalanced by one or |
| 13 | +more tree rotations. |
| 14 | + |
| 15 | +Animation showing the insertion of several elements into an AVL |
| 16 | +tree. It includes left, right, left-right and right-left rotations. |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +AVL tree with balance factors (green) |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +### AVL Tree Rotations |
| 25 | + |
| 26 | +**Left-Left Rotation** |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +**Right-Right Rotation** |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +**Left-Right Rotation** |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +**Right-Left Rotation** |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +## References |
| 43 | + |
| 44 | +* [Wikipedia](https://en.wikipedia.org/wiki/AVL_tree) |
| 45 | +* [Tutorials Point](https://www.tutorialspoint.com/data_structures_algorithms/avl_tree_algorithm.htm) |
| 46 | +* [BTech](http://btechsmartclass.com/DS/U5_T2.html) |
0 commit comments