Exercise 967Combinatorics › Graph theoryL1Added 3 Nov 2026
Diameter of a tree
#tree#diameter#BFS
Statement
Show that the diameter of a tree (longest shortest path) can be found by two BFS runs.
Hint
First BFS from any vertex; the farthest vertex is an endpoint of a diameter. Second BFS from there.
Show solutionHide solution
Solution
First BFS. Start from any vertex , find farthest vertex .
Claim. is an endpoint of a diameter.
Second BFS. Start from , find farthest vertex . Then is the diameter.
Conclusion. Two BFS runs compute the diameter of a tree in .