The AVL tree is a self-balancing binary search tree in which the heights of the two child sub-trees of any node differ by at most one. If at any time they differ by more than one, rebalancing is done by one or more tree rotations to restore this property. Basic operations such as lookup, insertion, deletion all take O(log n) time in both the average and worst cases, where n is the number of nodes in the tree prior to the operation. There are four ways to rotate nodes in an AVL tree (graphically represented):