Graph Theory37 sections · 1633 units
Open in Course

Path to LCA Structure

(Two paths meet at ancestor)

Any path from uu to vv splits into two parts: the path from uu up to lca(u,v)lca(u, v) and the path from lca(u,v)lca(u, v) down to vv. Both parts go up, from uu to lcalca and from vv to lcalca. Each part is a path from a node up to an ancestor. By the chain property, each part crosses O(logn)O(\log n) chains.

The full path crosses O(logn)O(\log n) chains total. To query a path, you walk up from uu to the LCA and from vv to the LCA, querying each chain segment you touch. You combine all the segment results.

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