Skip to main content

Diameter of a Tree

Learn Diameter of a Tree (Trees, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

What is the Diameter? The diameter is the length (number of edges) of the LONGEST path between any two nodes - and crucially, this path does NOT have to pass through the root. For any given node, the longest path THROUGH it equals leftHeight + rightHeight ; the answer is the maximum of this value across every node.

More lessons in Trees