Skip to content
StackDecode
Advanced data structuresExplained

Heavy-Light Decomposition

Split a tree into heavy chains so paths become few array ranges.

Time

O(log² n) path query

Extra space

O(n)

Use it for

Path queries on trees.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.