recursive method to set heights of nodes