Why it matters
LCA underlies many tree algorithms. Understanding enables tree problem solving.
Advertisement
The architecture
Binary lifting: for each node, store 2^k-th ancestor.
Euler tour + RMQ: linearize tree; LCA = RMQ on depth.
Advertisement
How it works end to end
Binary lifting: precompute in O(n log n); query O(log n).
Euler tour + sparse table RMQ: O(n log n) precomp; O(1) query.
Applications: path length = depth(u) + depth(v) - 2*depth(LCA).