Tree Diameter
DFS Twice
Pick a random node
i
.DFS to find the furthest node
j
to nodei
.DFS to find the furthest node
k
to nodej
.
The distance between j
and k
is the tree's diameter.
See proof
Problems
Last updated
Was this helpful?