Why it matters

DSU on Tree enables efficient subtree aggregations.

Advertisement

The architecture

Process heavy child first.

Keep its data; add light children data.

DSU on TreeHeavy child datakeptLight children dataadded + removedAmortized O(n log n)each node in O(log n) heavy pathsEach node in log n heavy paths from root; amortized argument
DSU on Tree logic.
Advertisement

How it works end to end

Applications: subtree color counts, distinct value counts.

Implementation: DFS with heavy inheritance.