Data Structures19 sections · 729 units
Open in Course

Operations We Need

The interface

A Link-Cut tree supports:

1.1. link(u, v): Make uu a child of vv. (Trees must be in different components.)

2.2. cut(u): Remove edge from uu to its parent.

3.3. findRoot(u): Find root of uu's tree.

4.4. pathQuery(u, v): Query aggregate (sum/min/max) on path from uu to vv.

5.5. pathUpdate(u, v, val): Update all nodes on path from uu to vv.

6.6. lca(u, v): Find lowest common ancestor.

All operations run in O(logn)O(\log n) amortized time. Space: O(n)O(n).