calculate distance between nodes within tree