Graph Theory37 sections · 1633 units
Open in Course

Binary Lifting - Complexity

(Preprocessing and query time)

Binary lifting preprocessing takes O(nlog⁡n)O(n \log n) time and space. You fill a table of nn rows and log⁡n\log n columns, where each entry takes O(1)O(1). A single DFS computes all depths in O(n)O(n) time. Each LCA query takes O(log⁡n)O(\log n) time because you iterate through at most log⁡n\log n powers of 22 twice: once to equalize depths, once to climb together.

For qq queries, total time is O(nlog⁡n+qlog⁡n)O(n \log n + q \log n). Space is O(nlog⁡n)O(n \log n) for the up table. This is fast enough for most competitive programming problems with n,q≤2×105n, q \leq 2 \times 10^5. The main bottleneck is the log⁡n\log n factor per query, which Euler tour + RMQ can eliminate.