D&C on Trees

Centroid decomposition preview.

D&C applies to trees via centroid decomposition.

Centroid: A node whose removal splits the tree into subtrees of size n/2\leq n/2.

Approach: 1.1. Find the centroid.

2.2. Solve the problem for paths through the centroid.

3.3. Remove the centroid, recurse on each subtree.

Why it works: The centroid exists for any tree. After O(logn)O(\log n) levels of decomposition, all nodes are processed.

Applications: Counting paths with specific properties, tree distance queries.

This is an advanced technique covered in the Graph Theory roadmap. The core idea is that D&C works on any structure where you can split into balanced parts.