get_levels function

Obtains the node levels from a tree.