finds the diameter of tree