Graph Theory37 sections · 1633 units
Open in Course

Intro

(Divide and conquer on trees)

You have solved tree problems with DFS and DP.

But some path-counting and distance problems do not fit those patterns. When you need to analyze all paths in a tree, not parent-child or root-to-leaf paths, standard approaches time out. Centroid decomposition does exactly that. It is a divide-and-conquer technique that recursively breaks trees into smaller parts, each with at most half the nodes.

This balanced splitting enables efficient whole-tree analysis. By the end of this section, you will count paths, answer distance queries, and recognize when centroid decomposition is the right tool.