Double BFS finds the diameter in passes:
BFS from any node. Find the farthest node .
BFS from . Find the farthest node .
The distance from to is the diameter. You do not need to try every starting node. The first BFS always lands on a diameter endpoint, no matter where you start. This runs in time and uses space. The Tree Diameter & Center section proves why this property holds and walks through a full example with code.