implement David's solution for determining if a tree is balanced