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
Pick a random node i
.
DFS to find the furthest node j
to node i
.
DFS to find the furthest node k
to node j
.
The distance between j
and k
is the tree's diameter.
See proof
Last updated