Graph Theory37 sections · 1633 units
Open in Course

Extension - LCA

Finding LCA

Binary lifting also solves the LCA problem: given two nodes uu and vv, find their lowest common ancestor. The idea: bring uu and vv to the same depth using binary lifting.

Then jump both upward simultaneously until they meet. This takes O(logn)O(\log n) per query. You will implement this in the next problem. LCA is one of the most common tree queries in competitive programming, and binary lifting gives you a clean O(logn)O(\log n) solution.