Graph Theory37 sections · 1633 units
Open in Course

Core Idea - Binary Search on Ancestors

(Finding the split point)

The binary lifting approach is a binary search on ancestors. You are searching for the deepest ancestor that both nodes share. When you level the nodes to the same depth, you ensure that any common ancestor is at the same distance from both. Then, when you jump them upward together, you are narrowing down the range of possible LCA positions.

Each jump eliminates half of the remaining possibilities. If jumping 2k2^k steps keeps them in different subtrees, you know the LCA is at least 2k2^k steps above. If it makes them the same, you know the LCA is closer. This binary search structure is why it runs in O(logn)O(\log n) time. You are halving the search space with each iteration.