Graph Theory37 sections · 1633 units
Open in Course

Core Idea - LCA via Euler Tour

(RMQ on depth array)

Full Euler tour creates sequence where each node appears multiple times. Between the first occurrence of uu and first occurrence of vv, the node with minimum depth is their LCA. Build array depth[i] = depth of node at position ii in tour.

Build RMQ structure (segment tree or sparse table) on depthdepth. For LCA query: find positions first[u] and first[v] in tour, query RMQ on range between them, return the node at the position with minimum depth.