Graph Theory37 sections · 1633 units
Open in Course

CSES 1131 Tree Diameter - Problem Statement

Tree Diameter (CSES)

Find the diameter of a tree with nn nodes and n1n-1 edges. Unlike the binary tree version, nodes can have any number of children. The input is an adjacency list, not pointer-based TreeNode objects.

The DP approach from LC 543543 still works here, but Double BFS gives a cleaner solution for general trees. You will solve this problem fully in the Tree Diameter & Center section using Double BFS. That section also compares both approaches side by side so you can see when each one fits better.