Why it matters

HLD enables efficient tree path queries. Understanding shapes advanced tree problems.

Advertisement

The architecture

Heavy child: subtree with most nodes.

Heavy edge to heavy child; others light.

Chain: consecutive heavy edges.

HLD structureHeavy edgesto biggest subtreeChainsconsecutive heavyPath = O(log n) chainssegment tree per chainAlternative: LCT (link-cut trees) support tree modifications too
HLD organization.
Advertisement

How it works end to end

Path query: split into segments on chains. Each segment is contiguous in chain array.

Segment tree per chain (or flattened tree): O(log n) per segment.

Total: O(log² n) per path query.