What is the time complexity of finding the diameter of a tree?

What is the time complexity of finding the diameter of a tree?

Approach: Analyze DFS/BFS traversal for longest path.

O(V + E), which simplifies to O(N) for a tree, using two BFS traversals or one DFS with height calculation.

Follow-up: Describe the two-BFS algorithm for finding the diameter.

Key concepts: longest path, traversal.