calculates each nodes depth