Graph Theory37 sections · 1633 units
Open in Course

Building the Decomposition Tree

(Recursive centroid finding)

Start with the full tree. Find its centroid cc. Mark cc as processed. Split the tree into components by removing cc. Recursively find centroids of each component. Store parent-child relationships in the decomposition tree. Each recursive call works on a tree with at most n/2n/2 nodes.

The recursion depth is O(logn)O(\log n), and each level processes all nn nodes once. You recompute subtree sizes for each component. Total time: O(nlogn)O(n \log n). You rebuild size arrays for each component, but the halving keeps it logarithmic. Space is O(n)O(n) for the tree structure.

Space complexity is O(n)O(n) for the data structures used.