nodeHeights function

Compute the heights above the root of each node