Graph Theory37 sections · 1633 units
Open in Course

Single Segment Tree Improvement

(Flatten all chains)

Instead of separate segment trees for each chain, use one segment tree of size nn. Assign each node a global position flat_pos[v]. During decomposition, maintain a global counter. Nodes in the same chain get consecutive positions. This way, chain cc occupying positions ll to rr maps directly to range [l,r][l, r] in the single segment tree.

This simplifies implementation. You only manage one segment tree instead of many. Space usage drops from O(nlog⁡n)O(n \log n) to O(n)O(n). Most implementations use this improvement.

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