Data Structures19 sections · 729 units
Open in Course

Centroid Decomposition - Structure

The centroid tree

Centroid decomposition builds a "centroid tree":

1.1. Find centroid cc of current tree

2.2. Make cc the root of current subtree in centroid tree

3.3. Mark cc as removed

4.4. For each component after removing cc, recursively decompose and attach as children of cc

The centroid tree has O(logn)O(\log n) depth. Every node in the original tree appears exactly once. The path from any node to the centroid tree root has length O(logn)O(\log n). This structure enables efficient queries: to answer a query about node vv, walk up the centroid tree from vv, processing each ancestor.