LCA & Binary Lifting

Data Structures & Algorithms · Advanced Trees & Queries · Advanced · 25 min

Find the lowest common ancestor of two tree nodes in O(log n) per query with a jump table, and reuse the same table for k-th ancestors and distances.

This lesson is part of TuringPath Pro. See plans.

What you will learn

  • The question: who is the lowest common ancestor?
  • The jump table: up[k][v]
  • Answering lca(u, v) in two phases
  • Free extras: k-th ancestor and distance

More in Advanced Trees & Queries

Previous: Max Flow, Min Cut & Bipartite Matching · Next: Sparse Tables: O(1) Range Minimum