Adding algorithm for checking if the tree is balanced.