Graph Theory37 sections · 1633 units
Open in Course

Paths Through Centroids

core idea for path problems

Every path in the original tree passes through some centroid in the decomposition. If a path does not pass through the current centroid, it lies entirely within one component after removal. You will process it in a deeper recursion level.

This means you can count all paths by processing paths through each centroid.

At centroid cc, count paths from cc to all nodes in its subtree, then combine paths from different subtrees. No path is missed. You avoid double-counting because each path is counted exactly once: at its lowest common ancestor in the decomposition tree. This is the foundation of path-counting algorithms.