implement algorithm for computing a diameter for a tree