Graph Theory37 sections · 1633 units
Open in Course

Comparing the Problems

Different distance queries

Tree Diameter: Find the single longest path. Use two-BFS or DP.

Tree Distances I: For each node, find its farthest node. Use diameter endpoints since farthest is always an endpoint.

Tree Distances II: For each node, find sum of distances to all nodes. Use rerooting DP since the sum changes predictably when you move the root.

Each problem teaches a different technique. Together they cover the main approaches to tree distance problems.