01The diameter: the longest distance
The diameter of a tree is the longest distance between any two of its vertices. In the lecture’s tree it runs from 13 to 10 through 12, 8, 5, 2, 1, 3 and 6: 8 edges. A tree can have more than one diameter (a Y shape with three equal arms has three), but they all have the same length.
The lecture’s first observation is a lemma: both ends of a diameter are always leaves. Proof by contradiction: suppose an end V of a longest path were not a leaf. Then V has a neighbour off the path, and one more step gives a path longer than the longest one. Contradiction.
Brute force would run BFS from every vertex and keep the largest distance seen: O(V²). The next two sections bring it down to O(V).