Tree Diameter

DFS Twice

  • 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

Problems

Last updated