Proof of correctness: Algorithm for diameter of a tree in graph theory
In order to find the diameter of a tree I can take any node from the tree, perform BFS to find a node which is farthest away from it and then perform BFS on that node. The greatest distance from the second BFS will yield the diameter. I am not sure how to prove this, though? I have tried using induction on the number of nodes, but there are too many cases. Any ideas would be much appreciated... Let's call the endpoint found by the first BFS x. The crucial step is proving that the x found in this first step always "works" -- that is, that it is always at one end of some longest path. (Note that