algorithm checkbalance(current precurrent is the node to start from balancing postcurrent height has been updated while tree balance is if needed restored through rotations if current left and current right current height - else current height max(height(current left),height(current right) end if if height(current leftheight(current right if height(current left leftheight(current left right rightrotation(current else leftandrightrotation(current end if else if height(current leftheight(current right- if height(current right leftheight(current right right leftrotation(current else rightandleftrotation(current end if end if end checkbalance insertion avl insertion operates first by inserting the given value the same way as bst insertion and then by applying rebalancing techniques if necessary the latter is only performed if the avl property no longer holdsthat is the left and right subtrees height differ by more than each time we insert node into an avl tree we go down the tree to find the correct point at which to insert the nodein the same manner as for bst insertionthen we travel up the tree from the inserted node and check that the node balancing property has not been violatedif the property hasn' been violated then we need not rebalance the treethe opposite is true if the balancing property has been violated