Graph Theory37 sections · 1633 units
Open in Course

Core idea 1 - Paths Through Centroid

(Divide by centroid)

Find the centroid cc. Every path either passes through cc or lies entirely within one component after removing cc. Paths through cc can be counted directly. Count paths passing through cc directly. Then recursively count paths in each component.

This avoids double-counting because paths within components are handled in deeper recursion levels. The recursion depth is O(logn)O(\log n) because components halve in size, so you process each node O(logn)O(\log n) times total across all recursion levels.